Skip to content
Browse files

Error message on stack too short

  • Loading branch information...
1 parent 75a8bc4 commit b5c55806643858197af97d82f4cd3519b8ea524a @singpolyma committed
Showing with 5 additions and 0 deletions.
  1. +5 −0 rpnr.l
View
5 rpnr.l
@@ -1,5 +1,6 @@
%{
#include <stdio.h>
+#include <stdlib.h>
#define HANDLE_FATAL(x) do { if(!(x)) { fputs("A fatal error occured.\n", stderr); abort(); } } while (0) /* Simple error handling */
/* Global stack */
size_t stack_size = 0;
@@ -42,6 +43,10 @@ char *pop() {
/* Process a "message" by popping top two elements and pushing the result */
void do_message(const char *message) {
+ if(stack_length < 2) {
+ fputs("Syntax error.\n", stderr);
+ exit(EXIT_FAILURE);
+ }
char *arg = pop();
char *obj = pop();
if(strcmp(message, "=") == 0 || strcmp(message, ":=") == 0) { /* Assignment (special case) */

0 comments on commit b5c5580

Please sign in to comment.
Something went wrong with that request. Please try again.