Stack overflow errors get detected correctly

This commit is contained in:
nplk84 2023-10-16 11:56:38 +02:00
parent 655da552de
commit 7d7b67f7f2

8
njvm.c
View File

@ -20,11 +20,13 @@
unsigned int programmSpeicher[1000];
// Stack
unsigned int stack[1000];
#define maxValues 1000
unsigned int stack[maxValues];
unsigned int current = 0;
void stackPush(unsigned int value) {
if (current > 100) {
if (current > (maxValues-1)) {
fprintf(stderr, "stack overflow\n");
exit(EXIT_FAILURE);
}
@ -37,7 +39,7 @@ unsigned int stackPop(void) {
fprintf(stderr, "stack underflow\n");
exit(EXIT_FAILURE);
}
return --current;
return stack[--current];
}
void version(void) {