diff --git a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs index 0b5fabdb..7f0ec69f 100644 --- a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs +++ b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs @@ -137,10 +137,15 @@ mkHFile useStl inPackage cf groups = unlines if useStl then render (nest 2 bufAppendString) else "", " void inline bufReset(void)", " {", - " cur_ = 0;", + " if (buf_) free(buf_);", " buf_size = " ++ nsDefine inPackage "BUFFER_INITIAL" ++ ";", - " resizeBuffer();", + " buf_ = (char *) malloc(buf_size);", + " if (!buf_) {", + " fprintf(stderr, \"Error: Out of memory while allocating buffer!\\n\");", + " exit(1);", + " }", " memset(buf_, 0, buf_size);", + " cur_ = 0;", " }", "", " void inline resizeBuffer(void)",