Stack overflow errors get detected correctly
This commit is contained in:
parent
655da552de
commit
7d7b67f7f2
8
njvm.c
8
njvm.c
@ -20,11 +20,13 @@
|
|||||||
unsigned int programmSpeicher[1000];
|
unsigned int programmSpeicher[1000];
|
||||||
|
|
||||||
// Stack
|
// Stack
|
||||||
unsigned int stack[1000];
|
#define maxValues 1000
|
||||||
|
|
||||||
|
unsigned int stack[maxValues];
|
||||||
unsigned int current = 0;
|
unsigned int current = 0;
|
||||||
|
|
||||||
void stackPush(unsigned int value) {
|
void stackPush(unsigned int value) {
|
||||||
if (current > 100) {
|
if (current > (maxValues-1)) {
|
||||||
fprintf(stderr, "stack overflow\n");
|
fprintf(stderr, "stack overflow\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -37,7 +39,7 @@ unsigned int stackPop(void) {
|
|||||||
fprintf(stderr, "stack underflow\n");
|
fprintf(stderr, "stack underflow\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
return --current;
|
return stack[--current];
|
||||||
}
|
}
|
||||||
|
|
||||||
void version(void) {
|
void version(void) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user