Cobol: Fix lexer overflow error with variable-length patterns.
Cobol lexer no longer overflows on long matches.
An internal compiler error in the COBOL lexer, triggered by an ‘input buffer overflow’ when processing long variable-length patterns, has been resolved. The fix uses flex’s input() and unput() functions to manage the input stream more effectively before pattern matching, preventing the overflow and associated errors.
In Details
The COBOL lexer (scan.l) previously had issues with variable-length patterns that could match up to EOF. This could lead to an 'input buffer overflow' error, especially when combined with REJECT (though REJECT was unused). The fix replaces potentially problematic pattern matching with explicit input() and unput() calls to pre-read and restore the input stream, resolving the overflow condition.
- lexer
- The component of a compiler that performs lexical analysis. It breaks the source code into a stream of tokens.
- input buffer overflow
- An error condition that occurs when a program attempts to write more data into a buffer than it can hold, potentially leading to data corruption or crashes.
- flex
- A lexical analyzer generator. It takes a description of lexical rules and generates C code for a scanner (lexer).
- REJECT
- A directive in
flexthat causes the current match to be abandoned and scanning to resume after the longest possible alternative match. In this case, it was found to be unused.