From 37bc01fb00fe0011f69cce9ed6a50ef916b7335c Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Fri, 26 Jan 2024 21:51:55 +0100 Subject: [PATCH] Fix SEGFAULT in check of prototype arguments --- cobc/ChangeLog | 5 +++++ cobc/parser.y | 9 ++++++--- tests/testsuite.src/syn_misc.at | 17 +++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 93a02ac96..0c70df5ce 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,9 @@ +2024-01-28 Fabrice Le Fessant + + * parser.y: fix SEGFAULT when checking BY VALUE arguments with + any length + 2023-11-29 Fabrice Le Fessant * cobc.c (cobc_clean_up): when save-temps specifies a directory, diff --git a/cobc/parser.y b/cobc/parser.y index 3b463150b..9d10d56e8 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -11026,9 +11026,12 @@ procedure_param: } if (call_mode == CB_CALL_BY_VALUE - && CB_REFERENCE_P ($4) - && CB_FIELD (cb_ref ($4))->flag_any_length) { - cb_error_x ($4, _("ANY LENGTH items may only be BY REFERENCE formal parameters")); + && CB_REFERENCE_P ($4)){ + cb_tree fx = cb_ref ($4); + if (fx != cb_error_node + && CB_FIELD (fx)->flag_any_length) { + cb_error_x ($4, _("ANY LENGTH items may only be BY REFERENCE formal parameters")); + } } $$ = CB_BUILD_PAIR (cb_int (call_mode), x); diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index 94ff7b0d0..27cb9e37d 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8364,7 +8364,9 @@ AT_DATA([prog.cob], [ *> BINARY-C-INT usage does not exist: error on purpose to *> trigger an error below 01 c USAGE BINARY-C-INT. - *> This one should also trigger an error, but does not... + *> level 78 triggers an error, but not the expected one: the + *> string replaces the identifier in the scanner, so it becomes + *> a syntax error 78 d-const VALUE "abc". PROCEDURE DIVISION USING a @@ -8376,16 +8378,11 @@ AT_DATA([prog.cob], [ END PROGRAM f. ]) -AT_CHECK([$COMPILE_ONLY -Wno-unfinished prog.cob], [134], [], +AT_CHECK([$COMPILE_ONLY -Wno-unfinished prog.cob], [1], [], [prog.cob:10: error: unknown USAGE: BINARY-C-INT -prog.cob:16: error: ANY LENGTH items may only be BY REFERENCE formal parameters - -cobc: ../../cobc/parser.y:11030: invalid cast from 'internal error node' type CONSTANT to type FIELD - -cobc: aborting compile of prog.cob at line 18 (PROGRAM-ID: f) - -cobc: Please report this! -Aborted (core dumped) +prog.cob:18: error: ANY LENGTH items may only be BY REFERENCE formal parameters +prog.cob:20: warning: optional period used +prog.cob:20: error: syntax error, unexpected Literal, expecting END PROGRAM ]) AT_CLEANUP