Skip to content

Commit

Permalink
Fix SEGFAULT in check of prototype arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Jan 31, 2024
1 parent 473a26c commit 43afbdc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 5 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2024-01-28 Fabrice Le Fessant <[email protected]>

* parser.y: fix SEGFAULT when checking the BY VALUE arguments of a
prototype with ANY LENGTH

2023-11-29 Fabrice Le Fessant <[email protected]>

* cobc.c (cobc_clean_up): when save-temps specifies a directory,
Expand Down
9 changes: 6 additions & 3 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 6 additions & 11 deletions tests/testsuite.src/syn_misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -8364,28 +8364,23 @@ 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 instead of a complain about level 78
78 d-const VALUE "abc".
PROCEDURE DIVISION
USING a
BY REFERENCE b
BY VALUE b
c
d-const
*> d-const
RETURNING OMITTED.
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
])

AT_CLEANUP
Expand Down

0 comments on commit 43afbdc

Please sign in to comment.