Fix segfault in 1996/august (but clang is broken)
The program segfaulted which prevented it from being used. This was due to addressing far out of bounds of the m array. This was discovered with a debugger. But a strange problem is that one cannot use -ggdb3 - -g works however. This is because it hangs. Now this entry will not work (at least a part or one of the invocations) with clang and that means that it won't work with macOS. Is it because of some debug symbols that are being generated or something else? I really do not know but the judges noted back then that some compilers compile it into an infinite loop (though the command they suggested did not have the problem - a later one did). I updated the bugs.md with details under the status of it does not work with some compilers. I also added the try.sh script as a convenience as there are a lot of commands to do.
This commit is contained in:
1 parent
4e2492f734
commit
738393c695
5 files changed
+75
-6
No files matched your search
@@ -4,3 +4,5 @@ test.oo
|
||||
fac.oo
|
||||
parse.oo
|
||||
prog.oc
|
||||
august.oo
|
||||
prog.oo
|
||||
@@ -38,7 +38,7 @@ include ../../var.mk
|
||||
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
CSILENCE= -Wno-error -Wno-implicit-function-declaration -Wno-invalid-source-encoding
|
||||
CSILENCE= -Wno-error -Wno-implicit-function-declaration -Wno-invalid-source-encoding -Wno-invalid-utf8
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
@@ -57,7 +57,7 @@ ARCH=
|
||||
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
CDEFINE= -DZ=60000 -D'T=m[s]' -D'P=m[s++]' \
|
||||
CDEFINE= -DZ=240000 -D'T=m[s]' -D'P=m[s++]' \
|
||||
-D'L=m[p++]' -D'g=getchar()' -DE=else -DW=while -D'B=m[p++]' \
|
||||
-DI=if -DR='s=s+l/2;T=r;I(l%2)s++' -D'X=m[s-' \
|
||||
-D'D=Q(13,-)Q(14,*)Q(15,/)Q(16,%)Q(6,==)Q(7,!=)Q(8,<)C(1,r=P;m[T]=r;T=r)C(9,r=P;m[T]=r;s++)'
|
||||
|
||||
+21
-4
@@ -20,12 +20,22 @@ cat august.c test.oc | ./august > test.oo
|
||||
```
|
||||
|
||||
|
||||
NOTE: Some compilers will compile this code into infinite loops!
|
||||
If the above cat line does not execute in a very short amount
|
||||
of time, then you may need to fix your compiler or use gcc.
|
||||
NOTE: Some compilers like clang will compile this code into infinite loops! If
|
||||
the above cat line (or one of the ones later in the try section) does not
|
||||
execute in a very short amount of time, then you may need to fix your compiler
|
||||
or use gcc.
|
||||
|
||||
It should print a `!` followed by a newline.
|
||||
The above should print a `!` followed by a newline.
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in
|
||||
this program that prevented it from working right but he notes it hangs in
|
||||
macOS. It works fine in linux. This is because macOS has clang, not gcc, even
|
||||
the gcc binary. He observed that with specific compiler flags it hangs in linux
|
||||
too and perhaps it's related to this in macOS; maybe other flags are needed but
|
||||
he doesn't know (at least not yet). He provided a bit more information in
|
||||
[bugs.md](/bugs.md) for anyone who wants to have a go at providing a fix for
|
||||
other compilers. As there are a lot of commands to try he also added
|
||||
[try.sh](try.sh). Thank you Cody for your assistance!
|
||||
|
||||
## Try:
|
||||
|
||||
@@ -75,6 +85,13 @@ And if you have lots of spare time, you can recurse one level deeper:
|
||||
cat august.oo august.oo august.oo fac.oo | ./august
|
||||
```
|
||||
|
||||
NOTE: to run all the commands in the above sections you can also use the
|
||||
[try.sh](try.sh) script like:
|
||||
|
||||
```sh
|
||||
./try.sh
|
||||
```
|
||||
|
||||
We (the judges) recommend that you spend some time studying this
|
||||
entry as it surely will make the 'best of the IOCCC' list. It was
|
||||
very well received by those who attended the IOCCC BOF.
|
||||
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
make clobber all
|
||||
set -x
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
./august < test.oo
|
||||
cat august.c fac.oc | ./august > fac.oo
|
||||
./august < fac.oo
|
||||
|
||||
cat august.c fac.oc | ./august | ./august
|
||||
|
||||
cat august.c parse.oc | ./august > parse.oo
|
||||
cat parse.oo fac.oc | ./august | ./august
|
||||
|
||||
rm august.oc
|
||||
make august.oc
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
cat august.oo test.oo | ./august
|
||||
cat august.oo august.oo fac.oo | ./august
|
||||
cat august.oo august.oo august.oo fac.oo | ./august
|
||||
@@ -800,6 +800,36 @@ We would appreciate anyone who has it or even just knows the name! Thank you.
|
||||
|
||||
# 1996
|
||||
|
||||
## [1996/august](1996/august/august.c) ([README.md](1996/august/README.md))
|
||||
## STATUS: doesn't work with some compilers - please provide alternative code
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in
|
||||
this program that prevented it from working but he observes that this hangs
|
||||
in macOS with this invocation in particular:
|
||||
|
||||
```sh
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
```
|
||||
|
||||
This happens to do with the fact that macOS is `clang` even the binary `gcc`.
|
||||
Trying clang in linux and the same problem occurs. As well if specifying (even
|
||||
with gcc) certain flags this also happens namely `-ggdb3`. The bug fix involved
|
||||
increasing the value of `Z` as it was accessing way out of range of the array,
|
||||
thus causing a segfault.
|
||||
|
||||
The compilation should look like:
|
||||
|
||||
```sh
|
||||
cc -std=gnu90 -Wall -Wextra -pedantic -Wno-error -Wno-implicit-function-declaration -Wno-invalid-source-encoding -Wno-invalid-utf8 -DZ=240000 -D'T=m[s]' -D'P=m[s++]' -D'L=m[p++]' -D'g=getchar()' -DE=else -DW=while -D'B=m[p++]' -DI=if -DR='s=s+l/2;T=r;I(l%2)s++' -D'X=m[s-' -D'D=Q(13,-)Q(14,*)Q(15,/)Q(16,%)Q(6,==)Q(7,!=)Q(8,<)C(1,r=P;m[T]=r;T=r)C(9,r=P;m[T]=r;s++)' -O3 august.c -o august
|
||||
```
|
||||
|
||||
but again this will not work with clang. As the judges noted that some compilers
|
||||
compile it into an infinite loop I'm (Cody) inclined to believe that this is the
|
||||
source of the problem.
|
||||
|
||||
Nevertheless if you have a fix for clang we welcome it!
|
||||
|
||||
|
||||
## [1996/gandalf](1996/gandalf/gandalf.c) ([README.md](1996/gandalf/README.md))
|
||||
## STATUS: missing or dead link - please provide them
|
||||
|
||||
|
||||
Reference in new issue
Block a user