format segfaults when given a format control sequence of '~s' and a number of character codes over a certain size
I ran into this while trying to output 64820 character codes. I then ran a few experiments to see when it would fail. I arrived at a failure point of 10265.
| ?- length(As, 10264), maplist(=(65), As), format('~s', [As]).
At this point 10264 As are printed without problem.
| ?- length(As, 10265), maplist(=(65), As), format('~s', [As]).
Here many As printed, not sure of it's 10264 or less, then followed by
Fatal Error: Segmentation Violation (bad address: 0x0)
% uname -a
Darwin arussell-armMBP-YX03 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:54 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6030 arm64
% gprolog --version
Prolog top-Level (GNU Prolog) 1.5.0
Copyright (C) 1999-2024 Daniel Diaz
Both queries succeed for me without errors or crashes using the latest git version on macOS Intel 14.7.2.
I just tried
length(As, 10265), maplist(=(65), As), format('~s', [As]).
on two other machines, both Arm based Macs running MacOS, with 1.5.0. In both cases I get the same segfault behavior.
Will try a very different system (Intel Windows) later today when I get a chance.
I can reproduce the crash on OSX 10.14.2:
... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Fatal Error: Segmentation Violation (bad address: 0x0)
Will try a very different system (Intel Windows) later today when I get a chance.
The Windows test wasn't very informative. The gprolog window would crash but before I could see any output. Possibly it segfaulted, but also possibly it was just a limitation of the gprolog window in displaying this amount of text.
You can run GNU Prolog on Windows from the command line (e.g. using PowerShell).
Will try a very different system (Intel Windows) later today when I get a chance.
The Windows test wasn't very informative. The gprolog window would crash but before I could see any output. Possibly it segfaulted, but also possibly it was just a limitation of the gprolog window in displaying this amount of text.
I just ran Prolog 1.5.0 on a Windows 10 system. This bug did not appear there. This was a different system than the first Windows computer I tried. In this case the gprolog window did not even crash.
So far this only seems to segfault on Apple Arm systems.