I am currently learning COBOL and upon learning COPY thought that maybe I could use it to create recursive loops. Instead, makes gnuCOBOL crash.
When I run cobc -free -O -C main.cob, I get this error:
unknown (signal)
cobc: aborting compile of fab.cob at line 5 (unknown: unknown)
cobc: Please report this!
I don't know if my code is valid COBOL, but presumably it shouldn't crash.
My output of cobc --version is
cobc (GnuCOBOL) 3.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built Apr 03 2025 01:34:43
Packaged Jul 28 2023 17:02:56 UTC
C version "14.2.1 20250207"
more specifically, the one that is automatically downloaded and compiled using this AUR script: https://aur.archlinux.org/packages/gnucobol
Sorry for not testing if this error also exists in trunk. I attempted to build trunk manually, and after running a ./autogen.sh and ./configure , make failed with
[...]
make all-recursive
make[1]: Entering directory '/home/plum/patches/gnucobol-code'
Making all in .
make[2]: Entering directory '/home/plum/patches/gnucobol-code'
make[2]: Leaving directory '/home/plum/patches/gnucobol-code'
Making all in lib
make[2]: Entering directory '/home/plum/patches/gnucobol-code/lib'
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pipe -finline-functions -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-y2k -MT dummymac.lo -MD -MP -MF .deps/dummymac.Tpo -c -o dummymac.lo dummymac.c
libtool: Version mismatch error. This is libtool 2.5.3, but the
libtool: definition of this LT_INIT comes from libtool 2.5.4.1-baa1-dirty.
libtool: You should recreate aclocal.m4 with macros from libtool 2.5.3
libtool: and run autoconf again.
make[2]: *** [Makefile:536: dummymac.lo] Error 63
make[2]: Leaving directory '/home/plum/patches/gnucobol-code/lib'
make[1]: *** [Makefile:698: all-recursive] Error 1
make[1]: Leaving directory '/home/plum/patches/gnucobol-code'
make: *** [Makefile:606: all] Error 2
I unfortunately have other things to do today than debug that. (I am also unfamiliar with GNU autoconfigure and related tools so it would take extra time)
Thank you for this nice reproducer. With current 3.3 nightly and C sanitizers enabled I see:
That is
and gdb shows that
new_text(a parameter passed by the caller) is indeedNULL.backtrace:
Which gets us to
so this is about the replacement... which gives us an ever more simple reproducer:
cobc -E main.cob -o /dev/nullI'll take care of this issue very soon, possibly also adjusting the message to drop the "(unknown: unknown)" part and try to get actual data in up-front.
You could try the following in ppparse.y (and/or ppparse.c directly to drop the need to regenerate it), which should fix that specific abort (but I haven't checked if this solves all issues around empty replacements):
Just FYI: You likely want to do the following to main.cob:
as the first only changes the source format if if is in non-fixed form already, while the second works on all formats (and also allow you to drop the
-freeduring your compiles).oh that is really clever and a good point, thank you for your help.
Last edit: Simon Sobisch 2025-06-25