https://gcc.gnu.org/g:fe37b9c1c4ecb5dbb3762755ad1bd6eccf524afd
commit r17-2313-gfe37b9c1c4ecb5dbb3762755ad1bd6eccf524afd Author: James K. Lowden <[email protected]> Date: Thu Jul 9 15:36:50 2026 -0400 cobol: Replace NUL input with space, with diagnostic. Old-school COBOL input may embed NUL characters in alphanumeric literals. GNU Flex unfortunately treats NUL as end-of-file marker. Detect the situation in the lexio file-reader. Replace NUL with SPACE, increment error count, and emit message. Fixes RT 3622. * lexio.h (parse_error_inc): Declare function. (struct filespan_t::next_line): Detect and remove NUL, Diff: --- gcc/cobol/lexio.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/lexio.h b/gcc/cobol/lexio.h index f58470d97e29..222a831fe6d4 100644 --- a/gcc/cobol/lexio.h +++ b/gcc/cobol/lexio.h @@ -112,7 +112,7 @@ struct bytespan_t { } }; -// YYLTYPE supplied by cbldiag.h. Borrowed from parse.h as generated by Bison. +size_t parse_error_inc(); struct filespan_t : public bytespan_t { char *cur, *eol, *quote; @@ -164,6 +164,19 @@ struct filespan_t : public bytespan_t { eol = std::find(cur, eodata, '\n'); + char *nul = std::find(cur, eol, '\0'); + if( nul != eol ) { + if( std::any_of( nul, eodata, + []( char ch ) { return ch != '\0'; } ) ) { + int icol = nul - cur; + fprintf(stderr, "%s:%d:%d: error: NUL character detected in input\n%*s\n", + cobol_filename(), int(iline + 1), ++icol, + int(eol - cur), cur); + parse_error_inc(); + std::replace(nul, eol, '\0', SPACE); + } + } + if( eol < eodata ) { ++eol; ++iline;
