GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
cobol

cobol: Replace NUL input with space, with diagnostic.

Fixes COBOL parsing by replacing embedded NUL characters with spaces and issuing a diagnostic message.

This commit addresses an issue in the COBOL compiler where NUL characters embedded within alphanumeric literals caused parsing errors, as the lexer treated NUL as an end-of-file marker. The code now detects NUL characters in the lexio file reader, replaces them with spaces, increments an error counter, and emits a diagnostic message. This ensures that COBOL source files with such characters can be processed correctly.

In Details

This commit modifies the lexio.h file for the COBOL front-end to handle NUL characters within alphanumeric literals. Previously, GNU Flex treated NUL as EOF, truncating input. The filespan_t::next_line function is updated to detect NUL, replace it with a space, increment parse_error_inc, and report the issue, effectively fixing RT 3622.

For Context
NUL character
A control character with the value zero. In C and many other programming contexts, it often signifies the end of a string. In lexical analysis, it can sometimes be misinterpreted as an end-of-file marker.
alphanumeric literal
A sequence of characters, including letters and numbers, treated as a single fixed value within a program. In COBOL, these are often used for string data.
lexio
Likely refers to the lexical input handling routines for the COBOL front-end, responsible for reading and processing source code character by character.
Flex
A fast lexical analyzer generator. It takes a description of lexical rules and generates C code that scans input text according to those rules.
diagnostic message
An informational message issued by the compiler to report potential issues, warnings, or errors. These messages help developers understand and fix problems in their code.
Filed Under: cobollexererror handlingcharacter encoding