From 61de38e6f0186ac3e613bac7c7b213a5d737dc6f Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 4 Jul 2023 08:41:12 -0700 Subject: [PATCH] Fix 2004/burley There were two things that had to change with my previous fix (getting it to compile), one in code and one in the Makefile. Instead of doing ',1' after the calls to longjmp() do ',0'. The way it originally was is in binary expressions but since the function returns void I made the result be 0 rather than 1 and along with the other change it works (though maybe it would work with 1 anyway but it seems not to be necessary and I don't feel like testing it now). The Makefile change is that it won't work right with the optimiser enabled so that was disabled. I removed this entry from bugs.md (which was listed twice by accident - and some other things were too) and updated it in the thanks-for-fixes.md file as well. --- 2004/burley/Makefile | 2 +- 2004/burley/burley.c | 32 +++++------ bugs.md | 134 +++++-------------------------------------- thanks-for-fixes.md | 19 +++--- 4 files changed, 41 insertions(+), 146 deletions(-) diff --git a/2004/burley/Makefile b/2004/burley/Makefile index b5ac4c3a5..1117fd2bb 100644 --- a/2004/burley/Makefile +++ b/2004/burley/Makefile @@ -66,7 +66,7 @@ CINCLUDE= -include stdio.h -include setjmp.h -include string.h -include time.h - # Optimization # -OPT= -O3 +OPT= # Default flags for ANSI C compilation # diff --git a/2004/burley/burley.c b/2004/burley/burley.c index cdaa2c222..2b89cb8fe 100644 --- a/2004/burley/burley.c +++ b/2004/burley/burley.c @@ -19,31 +19,31 @@ setjmp(p[0]), setjmp(p[3]), (i||!++i)&&((h--||(k|=i), i/=2, -longjmp(p[3],4)),1), -longjmp(p[0],1)),1), +longjmp(p[3],4)),0), +longjmp(p[0],0)),0), k^=-1, k+=1<<037, setjmp(p[3]), k&&(((--i<5&&1&k)&&(s=(rand()>>9)%0x4, setjmp(p[0]), t+=(rand()>>3)%015-t, -e[s]&(1<>=1, i+=1<<1, -longjmp(p[3],4)),1), +longjmp(p[3],4)),0), setjmp(p[0]), putchar(0x20+!putchar(012+"(.7-A,G+@*J)/"[(017&(i=g[4-k]))*013%13])), -++k^005&&(longjmp(p[0],1),1), +++k^005&&(longjmp(p[0],0),0), putchar('\n'), setjmp(p[3]), putchar(0x1F+!!putchar(("BCDHS"[g[--k]>>4]))), -k&&(longjmp(p[3],4),1), +k&&(longjmp(p[3],4),0), putchar('\n'), j+=1<<0, 1^j||(d=(char*)fgets(a,sizeof a, stdin)), -longjmp(p[1],2)),1), +longjmp(p[1],2)),0), s=1==(f=0), i=0<<1, setjmp(p[3]), @@ -53,13 +53,13 @@ j<5&&(((017&g[j])>(g[i]&15)&&(k=g[i], g[i]=g[j], g[j]=k), j++, -longjmp(p[1],2)),1), +longjmp(p[1],2)),0), i++, -longjmp(p[3],4)),1), +longjmp(p[3],4)),0), setjmp(p[0]), -i--&&!((g[1+i]^g[i])>>4)&&(longjmp(p[0],1),1), +i--&&!((g[1+i]^g[i])>>4)&&(longjmp(p[0],0),0), setjmp(p[1]), ---j&&(!(k=(g[j]&15)-(g[j-1]&017)+1)||(!(j-1)&&(8==-k)))&&(longjmp(p[1],2),1), +--j&&(!(k=(g[j]&15)-(g[j-1]&017)+1)||(!(j-1)&&(8==-k)))&&(longjmp(p[1],2),0), s+=3*!j|!(++i^17), (j*=i*=4)&&(i=1), setjmp(p[3]), @@ -68,9 +68,9 @@ setjmp(p[1]), 5-i>j&&(((g[j]^g[j+1])&0xf?g[j]^=g[j]:(s+=((g[j]&0xf)>8&&f++, !!g[j]*i)), j++, -longjmp(p[1],2)),1), +longjmp(p[1],2)),0), i++, -longjmp(p[3],4)),1), +longjmp(p[3],4)),0), s=1^s?"AACEDJQZHello World"[s]-'A':!!f, s+=(!i)*(6+12*s-!!s*((g[2]&017)^0xa?8:-192)), s--, @@ -84,10 +84,10 @@ setjmp(p[0]), setjmp(p[1]), 0<=j&&((e[i+j]^=*(i-j+e+(j<<1)), --j, -longjmp(p[1],2)),1), +longjmp(p[1],2)),0), i+=i+1, -longjmp(p[0],1)),1), -longjmp(p[2],3)),1)); +longjmp(p[0],0)),0), +longjmp(p[2],3)),0)); } int main(int argc, char**d){ (void)argc; diff --git a/bugs.md b/bugs.md index c80a3b4ad..3fee61baa 100644 --- a/bugs.md +++ b/bugs.md @@ -252,9 +252,9 @@ fixed he did it by adding a function called `pain()`. :-) clang** despite the fact it might appear to be gcc: no symlink and both gcc and clang exist but the gcc is clang which you'll see if you run `gcc --version`. -A tip and some fix methods from Cody: in the older days args not given a type -were implicit ints but when they're required to be char ** this can cause a -problem. In some cases Cody was able to use a char * inside main() (see +A tip and some fix methods from Cody: in the older days args to main() not given +a type were implicit ints but when they're required to be char ** this can cause +a problem. In some cases Cody was able to use a char * inside main() (see [1989/tromp/tromp.c](1989/tromp/tromp.c) and [1986/holloway/holloway.c](1986/holloway) for two examples though done slightly differently). In other cases he was able to dereference the pointers to be used @@ -606,6 +606,7 @@ This entry will very likely crash or do something strange without an arg. This entry will also enter an infinite loop if input is not a number > 0. + # 1991 ## [1991/dds](1991/dds/dds.c) ([README.md)(1991/dds/README.md)) @@ -643,8 +644,8 @@ possibility. Can you find out how? ## [1992/buzzard.1](1992/buzzard.1/buzzard.1.c) ([README.md](1992/buzzard.1/README.md)) ## STATUS: INABIAF - please **DO NOT** fix -This entry will crash without enough args (2). At this time this is not -considered a bug to fix so it should not be fixed. +This entry will crash without enough args (2). + ## [1992/kivinen](1992/kivinen/kivinen.c) ([README.md](1992/kivinen/README.md)) ## STATUS: known bug - please help us fix @@ -669,7 +670,7 @@ This program and the alternate version will very likely crash or [nuke](https://en.wikipedia.org/wiki/Nuclear_weapon) the [entire world](https://en.wikipedia.org/wiki/Earth) or just the [USA](https://en.wikipedia.org/wiki/United_States), respectively, without enough -args. This should not be fixed. +args. This should not be fixed! :-) # 1993 @@ -700,11 +701,12 @@ else. This should NOT be fixed. ## STATUS: known bug - please help us fix [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to compile -with modern systems (see the README.md file for what had to change) but the -entry also used `gets()` which in some systems would print out a warning along -with the output of the program. Naturally it could also overflow long lines. -Cody changed it to `fgets()` to prevent the display problem but this introduces -another problem namely that newlines can be printed if the line length < 231. +with modern systems (see the [thanks-for-fixes.md](thanks-for-fixes.md) file for +what had to change) but the entry also used `gets()` which in some systems would +print out a warning along with the output of the program. Naturally it could +also overflow long lines. Cody changed it to `fgets()` to prevent the display +problem but this introduces another problem namely that newlines can be printed +if the line length < 231. This seems like a worthy compromise but it would be ideal for it to never print a newline unless that's the line itself (a blank line). @@ -1182,7 +1184,6 @@ animation but this does not seem to work with modern gcc versions. It appears that version 2.95 works but maybe others do as well. Do you have a fix? We would appreciate your help! -Do you have a fix for 64-bit compilation? Please provide it! ## [2001/kev](2001/kev/kev.c) ([README.md](2001/kev/README.md) ## STATUS: INABIAF - please **DO NOT** fix @@ -1231,56 +1232,8 @@ There was no IOCCC in 2002. There was no IOCCC in 2003. -# 2004 -## [2004/burley](2004/burley/burley.c) ([README.md](2004/burley/README.md)) -## STATUS: known bug - please help us fix - -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to compile -with clang. He notes however that both prior to the fix (with gcc) and after the -fix (gcc, clang) it does not work: it allows input of the bet but after it -prints the hand it does not do anything with your next move. Cody provided the -following notes and tips (including possible reasons it doesn't work): - -0. Originally the `jmp_buf` was just an `int p[4][1000]`. -1. The `setjmp.h` header file was not included so the calls to `longjmp()` had -not only the wrong number of arguments but also implicitly returned int when it -actually returns void. This means that the comma operator had to be used to get -the binary expressions to work. It might be this is part of the problem. It's -possible that actually changing this introduced it to not work as some old -entries actually use invalid prototypes and work but changing them to use the -proper prototype breaks them. -2. Another possible problem is the abuse of `setjmp()` and `longjmp()` which is -known to be a problem, at least as he interprets it in his tired head (and less -experience with `longjmp`). In particular: - > The longjmp() routines may not be called after the routine which called the - > setjmp() routines returns. - See also the NOTES section of the linux man pages for `setjmp(3)` and - `longjmp(3)`. -3. The main() originally returned a call to main() which appeared to be an -infinite recursion at least as it was; now it returns a call to poke() (since -it's a poker game) which has the same number and type of args (1, `char *`) that -main() originally had. This appears to not be an infinite recursion but I might -be reading it wrong. Changing it to not return itself and the same problem -occurs so perhaps this is not the problem. It's possible that the initial call -to the `poke()` function is incorrect. -4. It might be that the requirement of the comma operator in modern compilers is -a problem. Perhaps some instances of `,1` should be `,0`? That seems plausible -as they are often used with the `&&` operator. -5. As well main() had only one arg, a `char *`, and there was a (seemingly) -needless cast to `char *` from gets(). This cast remains in the code however. -6. The code no longer uses `gets()` but `fgets()`; this is not the problem -however. -7. Sometimes the lack of a _proper_ prototype lets code work if the function is -used incorrectly so one should be careful with adding the proper prototypes. -With this entry it didn't _appear_ to be relevant but maybe it is after another -change? - -# 1997 - -There was no IOCCC in 1997. - # 1998 ## [1998/schnitzi](1998/schnitzi/schnitzi.c) ([README.md](1998/schnitzi/README.md)) @@ -1325,12 +1278,6 @@ There was no IOCCC in 1999. # 2000 -## [2000/dlowe](2000/dlowe/dlowe.c) ([README.md](2000/dlowe/README.md)) -## STATUS: doesn't work with some platforms - please help us fix - -This entry crashes in macOS. This will be looked at later. - - [2000/primenum](2000/primenum/primenum.c) ([README.md](2000/primenum/README.md)) ## STATUS: INABIAF - please **DO NOT** fix @@ -1393,49 +1340,6 @@ There was no IOCCC in 2003. # 2004 -## [2004/burley](2004/burley/burley.c) ([README.md](2004/burley/README.md)) -## STATUS: known bug - please help us fix - -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to compile -with clang. He notes however that both prior to the fix (with gcc) and after the -fix (gcc, clang) it does not work: it allows input of the bet but after it -prints the hand it does not do anything with your next move. Cody provided the -following notes and tips (including possible reasons it doesn't work): - -0. Originally the `jmp_buf` was just an `int p[4][1000]`. -1. The `setjmp.h` header file was not included so the calls to `longjmp()` had -not only the wrong number of arguments but also implicitly returned int when it -actually returns void. This means that the comma operator had to be used to get -the binary expressions to work. It might be this is part of the problem. It's -possible that actually changing this introduced it to not work as some old -entries actually use invalid prototypes and work but changing them to use the -proper prototype breaks them. -2. Another possible problem is the abuse of `setjmp()` and `longjmp()` which is -known to be a problem, at least as he interprets it in his tired head (and less -experience with `longjmp`). In particular: -> The longjmp() routines may not be called after the routine which called the -> setjmp() routines returns. -See also the NOTES section of the linux man pages for `setjmp(3)` and -`longjmp(3)`. -3. The main() originally returned a call to main() which appeared to be an -infinite recursion at least as it was; now it returns a call to poke() (since -it's a poker game) which has the same number and type of args (1, `char *`) that -main() originally had. This appears to not be an infinite recursion but I might -be reading it wrong. Changing it to not return itself and the same problem -occurs so perhaps this is not the problem. It's possible that the initial call -to the `poke()` function is incorrect. -4. It might be that the requirement of the comma operator in modern compilers is -a problem. Perhaps some instances of `,1` should be `,0`? That seems plausible -as they are often used with the `&&` operator. -5. As well main() had only one arg, a `char *`, and there was a (seemingly) -needless cast to `char *` from gets(). This cast remains in the code however. -6. The code no longer uses `gets()` but `fgets()`; this is not the problem -however. -7. Sometimes the lack of a _proper_ prototype lets code work if the function is -used incorrectly so one should be careful with adding the proper prototypes. -With this entry it didn't _appear_ to be relevant but maybe it is after another -change? - ## [2004/gavin](2004/gavin/gavin.c) ([README.md](2004/gavin//README.md)) ## STATUS: compiled executable crashes - please help us fix @@ -1654,7 +1558,7 @@ in the process some of the generated code fails. What might the translation of the comment end up being? Here's an example: -```c +``` system(" echo Line 2;sed -n -e 2,77p out> c.c;cc c.c -c "); ``` @@ -1695,7 +1599,6 @@ does not exist. This entry requires that `sed` and `cc` are in the path. - ## [2005/mynx](2005/mynx/mynx.c) ([README.md](2005/mynx/README.md)) ## STATUS: INABIAF - please **DO NOT** fix @@ -2082,15 +1985,6 @@ Abort trap: 6 but this is expected and the file `ioccc.html` will be generated properly. -## [2018/poikola](2018/poikola/prog.c) ([README.md](2018/poikola/README.md])) -## STATUS: INABIAF - please **DO NOT** fix - -Some have reported that Terminal.app in macOS does not work and one might need a -different terminal emulator like that from [XQuartz](https://www.xquartz.org) -but [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) reported that this -works fine in macOS Ventura with Terminal.app. YMMV of course. - - # 2019 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index eb322e282..614f3792e 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -926,11 +926,10 @@ your keyboard instead of the more awkward '`,`' and '`.`'. ## [2001/westley](2001/westley/westley.c) ([README.md](2001/westley/README.md])) -Cody added the script -[westley.sh](westley.sh) to automate a heap of commands that we, the IOCCC -judges, suggested, as well as some additional ones that he thought would be fun. -He also provided the sort and punch card versions that he added, described in -the README.md, based on the author's remarks. +Cody added the script [westley.sh](westley.sh) to automate a heap of commands +that we, the IOCCC judges, suggested, as well as some additional ones that he +thought would be fun. He also provided the sort and punch card versions that he +added, described in the README.md, based on the author's remarks. ## [2004/arachnid](2004/arachnid/arachnid.c) ([README.md](2004/arachnid/README.md])) @@ -941,10 +940,12 @@ Dvorak typists are invited to get lost (or use the original version)! :-) ## [2004/burley](2004/burley/burley.c) ([README.md](2004/burley/README.md])) -Cody fixed this to compile with clang which requires that the first arg of -main() be an int and the remaining args to be a `char **`. Compile but not work. -It did not work before the fix when compiled with gcc and it does not work with -clang either. See [/bugs.md](/bugs.md) for information. +Cody fixed this to compile with clang and also fixed it to work. A problem was +that `longjmp()` was being used with one arg which compiled because `setjmp.h` +was not included. Another part of the `setjmp()`/`longjmp()` situation was that +instead of `jmp_buf` the array `p` was of `int`. Finally the optimiser cannot be +enabled. As for clang it is because of the defect where the first arg must be an +int and the rest must be a `char **`. ## [2004/gavin](2004/gavin/gavin.c) ([README.md](2004/gavin/README.md]))