https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123847
Bug ID: 123847
Summary: Uninitialized public string variable in a module
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: algol68
Assignee: algol68 at gcc dot gnu.org
Reporter: mnabipoor at gnu dot org
Target Milestone: ---
Hi.
Tried to compile and run this example from documentation:
This module file:
module Logger =
def int fd = stderr;
pub string originator;
pub proc log = (string msg) void:
fputs (fd, (originator /= "" | ": ") + msg + "'n");
log ("beginning of log'n")
postlude
log ("end of log'n")
fed
And this program file:
access Logger
begin { Identify ourselves with the program name }
originator := argv (1);
proc parse_input = (string s) bool: skip,
write_output = (string s) bool: skip;
{ Read input file. }
if NOT parse_input (argv (2))
then log ("error parsing input file"); stop fi;
{ Write output file. }
if NOT write_output (argv (3))
then log ("error writing output file"); stop fi;
log ("success")
end
I compiled like this:
ga68 -ggdb3 -c logger.a68
ga68 -ggdb3 program.a68 logger.o
And run like this:
./a.out
which led to Segmentation fault.
In gdb, crash happens while executing this line:
fputs (fd, (originator /= "" | ": ") + msg + "'n");
which is calling __ga68_string_concat3922 function:
#0 0x0000000000401ac5 in __ga68_string_concat3922 (s1=..., s2=...)
(gdb) info args
s1 = {triplets% = {{lb% = 0, ub% = 0, stride% = 0}}, elements% = 0x0,
elements_size% = 0}
s2 = {triplets% = {{lb% = 1, ub% = 17, stride% = 4}}, elements% =
0x7ffff7dfafa0, elements_size% = 68}
(gdb)
which seems like `originator' is not initialized to empty string.