simplest reproducer:
$> echo 'MOVE 5 TO typo' | cobc -frelax-syntax -w -free - -t - -Xref 1>/dev/null
<stdin>:1: error: 'typo' is not defined
free(): invalid pointer
Does not happen with GC 3.1, but since GC 3.2.
The reason is that cobc_xref_set_receiving() expects a reference - but does not check the type of the reference (here the error node) and simply casts that to a field, something that is only asserted with --enable-cobc-internal-checks during configure, which leads to
cobc: cobc.c:6108: invalid cast from 'internal error node' type CONSTANT to type FIELD
cobc: aborting compile of <stdin> at line 2 (PROGRAM-ID: a)
cobc: Please report this!
fixed by the following patch
@@ -6122,10 +6097,15 @@
if (CB_CAST_P (target)) {
target = CB_CAST (target)->val;
}
- if (!CB_REF_OR_FIELD_P (target)) {
+ if (CB_REFERENCE_P (target)) {
+ /* note: we may get cb_error_node out here... */
+ target = cb_ref (target);
+ }
+ /* ... which is no field */
+ if (!CB_FIELD_P (target)) {
return;
}
- target_fld = CB_FIELD_PTR (target);
+ target_fld = CB_FIELD (target);
target_fld->count++;
#ifdef COB_INTERNAL_XREF
if (CB_REFERENCE_P (target)) {