From baec52c9013b344f2ab38c58543164897d061208 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 29 Oct 2023 08:25:08 -0700 Subject: [PATCH 1/3] Remove 1986/hague alt code, make main entry I fixed it so that the form where it would segfault (after printing the correct output) no longer occurs. The thanks file has had a note added towards the top about changing to fgets(), noting that although more is mentioned in the FAQ, it can be a real problem with some systems. The best example of it being beneficial is 1990/tbr. Naturally I also updated the thanks file for 1986/hague too, updating the details. --- 1986/hague/Makefile | 8 +++----- 1986/hague/README.md | 22 ---------------------- 1986/hague/hague.alt.c | 2 +- 1986/hague/hague.c | 4 ++-- thanks-for-fixes.md | 23 +++++++++++++++-------- 5 files changed, 21 insertions(+), 38 deletions(-) diff --git a/1986/hague/Makefile b/1986/hague/Makefile index efab15ec6..ca65c8fe8 100644 --- a/1986/hague/Makefile +++ b/1986/hague/Makefile @@ -63,7 +63,7 @@ CDEFINE= # Include files that are needed to compile # -CINCLUDE= -include stdio.h -include unistd.h +CINCLUDE= -include stdio.h -include unistd.h -include string.h # Optimization # @@ -114,8 +114,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= ${PROG}.alt.o -ALT_TARGET= ${PROG}.alt +ALT_OBJ= +ALT_TARGET= ################# @@ -131,8 +131,6 @@ all: data ${TARGET} sandwich supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c - @echo "NOTE: this entry uses gets() so you might get a warning about this" - @echo " when compiling and running this program with some systems." ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} # alternative executable diff --git a/1986/hague/README.md b/1986/hague/README.md index c533579c4..07e689cc5 100644 --- a/1986/hague/README.md +++ b/1986/hague/README.md @@ -9,10 +9,6 @@ UK make all ``` -There is an alternate version which uses `fgets()`. See the Alternate code -section below as well as the [bugs.md](/bugs.md) file for more details as to why -it is worth having as an alternate version. - ## To use: ```sh @@ -35,24 +31,6 @@ Also try: echo IOCCC | ./hague 2>/dev/null ``` -## Alternate code: - -Whereas with some entries the change to `fgets()` (see the [FAQ](/faq.md) for -details on why this has been done) can be done in the original code this entry -is more complicated in that although both forms of input show the correct -output, one form segfaults after the output. - -If you wish to use this alternate code, do: - -```sh -make alt -``` - -Use `hague.alt` as you would `hague` above. As for which form will segfault -after outputting the text it is when text is piped into the program. Again see -the [bugs.md](/bugs.md) file for more details. - - ## Judges' remarks: diff --git a/1986/hague/hague.alt.c b/1986/hague/hague.alt.c index c5dc9dba3..49973a91e 100644 --- a/1986/hague/hague.alt.c +++ b/1986/hague/hague.alt.c @@ -12,7 +12,7 @@ DITDAH _DIT,DITDAH DAH_,DITDAH DIT_, DITDAH _DIT_,DITDAH DIT_DAH DIT DAH,DITDAH DAH_DIT DIT DAH;DAHDIT DIT _DIT=DIT_DAH DIT 81 DAH,DIT_=_DIT -__DAH;_DIT=DAH_DIT DIT _DIT,81,stdin DAH,_DIT[strlen(_DIT)-1]='\0',_DIT!=NULL;__DIT +__DAH;_DIT==DAH_DIT DIT _DIT,81,stdin DAH&&(_DIT[strlen(_DIT)-1]='\0',_DIT);__DIT DIT'\n'DAH DAH DAHDIT DIT DAH_=_DIT;DITDAH DAH_;__DIT DIT DITDAH _DIT_?_DAH DIT DITDAH DIT_ DAH:'?'DAH,__DIT diff --git a/1986/hague/hague.c b/1986/hague/hague.c index bf43532b3..49973a91e 100644 --- a/1986/hague/hague.c +++ b/1986/hague/hague.c @@ -4,7 +4,7 @@ #define DITDAH * #define DAHDIT for #define DIT_DAH malloc -#define DAH_DIT gets +#define DAH_DIT fgets #define _DAHDIT char _DAHDIT _DAH_[]="ETIANMSURWDKGOHVFaLaPJBXCYZQb54a3d2f16g7c8a90l?e'b.s;i,d:" ;main DIT DAH{_DAHDIT @@ -12,7 +12,7 @@ DITDAH _DIT,DITDAH DAH_,DITDAH DIT_, DITDAH _DIT_,DITDAH DIT_DAH DIT DAH,DITDAH DAH_DIT DIT DAH;DAHDIT DIT _DIT=DIT_DAH DIT 81 DAH,DIT_=_DIT -__DAH;_DIT==DAH_DIT DIT _DIT DAH;__DIT +__DAH;_DIT==DAH_DIT DIT _DIT,81,stdin DAH&&(_DIT[strlen(_DIT)-1]='\0',_DIT);__DIT DIT'\n'DAH DAH DAHDIT DIT DAH_=_DIT;DITDAH DAH_;__DIT DIT DITDAH _DIT_?_DAH DIT DITDAH DIT_ DAH:'?'DAH,__DIT diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 942a90526..571b5ec1c 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -100,6 +100,18 @@ be made consistent but adding markdown where necessary in the remarks is). A lot of these fixes were done with his [sgit tool](https://github.com/xexyl/sgit) but many were done manually as well. +## A note about changes `fgets()` + +Although this is discussed in the [FAQ](/faq.md) we want to say here simply that +the problem with `gets()` is that in some systems a warning can be interspersed +with the output which can be confusing, to say nothing of the annoyance of it. A +good example was [1990/tbr](/thanks-for-fixes.md#1990tbr-readmemd) where one +would see: + + +```sh +$ warning: this program uses gets(), which is unsafe. +``` ## [1984/anonymous](1984/anonymous/anonymous.c) ([README.md](1984/anonymous/README.md)) @@ -292,14 +304,9 @@ commented out. ## [1986/hague](1986/hague/hague.c) ([README.md](1986/hague/README.md])) -Cody added alt code that uses `fgets()` to avoid alarming and annoying warnings -about `gets()` being unsafe. The reason this is alt code, at least for now, is -that although it will print the results in both forms of invocation, after the -output in one invocation form it will segfault. This might be addressed later on -or it might be decided that it is worth it, with a caveat in the Makefile or at -least the README.md file, since it still prints out the correct output, though -that seems like it might not be so ideal unless it can be fixed (which might be -done). See the [bugs.md](/bugs.md) file for details. +Cody made this use `fgets()` to avoid alarming and annoying messages about +`gets()` being unsafe, sometimes interspersed with the output of the program. +For more details about that see the [FAQ](/faq.md). ## [1986/holloway](1986/holloway/holloway.c) ([README.md](1986/holloway/README.md])) From 6d59b41a6b0fb58c9e3d66c3d2180f6085d536df Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:00:33 -0700 Subject: [PATCH 2/3] Remove outdated warning in 1989/westley/Makefile It is no longer true that it uses non-standard args to main() as of my fix in eb9e69fde657acc8c85a618a8a99af4c2f93b21d. --- 1989/westley/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/1989/westley/Makefile b/1989/westley/Makefile index 636320e39..a6f51e71b 100644 --- a/1989/westley/Makefile +++ b/1989/westley/Makefile @@ -132,7 +132,6 @@ all: data ${TARGET} sandwich supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c - @echo "NOTE: This entry uses non-standard args to main() that do not work with some modern compilers." ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} # alternative executable From d86e30de7b3f2f564f3660e81db2bac63e145d6a Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:29:26 -0700 Subject: [PATCH 3/3] Check if +x in 1989/westley/try.sh Check that program is executable before trying to use it. --- 1989/westley/try.sh | 125 ++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/1989/westley/try.sh b/1989/westley/try.sh index 359b47730..2d18abb70 100755 --- a/1989/westley/try.sh +++ b/1989/westley/try.sh @@ -1,70 +1,93 @@ #!/usr/bin/env bash -make all || exit 1 +# first compile everything or at least try to +./compile.sh -echo "$ echo IOCCC | ./westley" -echo IOCCC | ./westley -echo +if [[ -e "./westley" ]]; then + echo "$ echo IOCCC | ./westley" + echo IOCCC | ./westley + echo -echo "$ echo IOCCC | ./westley 1" -echo IOCCC | ./westley 1 -echo + echo "$ echo IOCCC | ./westley 1" + echo IOCCC | ./westley 1 + echo -echo "$ echo IOCCC | ./westley 1 2" -echo IOCCC | ./westley 1 2 -echo + echo "$ echo IOCCC | ./westley 1 2" + echo IOCCC | ./westley 1 2 + echo -echo "$ echo IOCCC | ./westley 1 2 3" -echo IOCCC | ./westley 1 2 3 -echo + echo "$ echo IOCCC | ./westley 1 2 3" + echo IOCCC | ./westley 1 2 3 + echo +fi -echo "$ echo IOCCC | ./ver0" -echo IOCCC | ./ver0 -echo +if [[ -e "./ver0" ]]; then + echo "$ echo IOCCC | ./ver0" + echo IOCCC | ./ver0 + echo -echo "$ echo Version 1 | ./ver1" -echo Version 1 | ./ver1 -echo + echo "$ echo IOCCC | ./ver0 1" + echo IOCCC | ./ver0 1 + echo -echo "$ echo Version 1 | ./ver1 1" -echo Version 1 | ./ver1 1 -echo + echo "$ echo IOCCC | ./ver0 1 2" + echo IOCCC | ./ver0 1 2 + echo -echo "$ echo Version 1 | ./ver1 1 2" -echo Version 1 | ./ver1 1 2 -echo + echo "$ echo IOCCC | ./ver0 1 2 3" + echo IOCCC | ./ver0 1 2 3 + echo +fi -echo "$ echo Version 1 | ./ver1 1 2 3" -echo Version 1 | ./ver1 1 2 3 -echo +if [[ -e "./ver1" ]]; then + echo "$ echo Version 1 | ./ver1" + echo Version 1 | ./ver1 + echo -echo "$ echo Version 2 | ./ver2" -echo Version 2 | ./ver2 -echo + echo "$ echo Version 1 | ./ver1 1" + echo Version 1 | ./ver1 1 + echo -echo "$ echo Version 2 | ./ver2 1" -echo Version 2 | ./ver2 1 -echo + echo "$ echo Version 1 | ./ver1 1 2" + echo Version 1 | ./ver1 1 2 + echo -echo "$ echo Version 2 | ./ver2 1 2" -echo Version 2 | ./ver2 1 2 -echo + echo "$ echo Version 1 | ./ver1 1 2 3" + echo Version 1 | ./ver1 1 2 3 + echo +fi -echo "$ echo Version 2 | ./ver2 1 2 3" -echo Version 2 | ./ver2 1 2 3 -echo +if [[ -e "./ver2" ]]; then + echo "$ echo Version 2 | ./ver2" + echo Version 2 | ./ver2 + echo -echo "$ echo Version 3 | ./ver3" -echo Version 3 | ./ver3 -echo + echo "$ echo Version 2 | ./ver2 1" + echo Version 2 | ./ver2 1 + echo -echo "$ echo Version 3 | ./ver3 1" -echo Version 3 | ./ver3 1 -echo + echo "$ echo Version 2 | ./ver2 1 2" + echo Version 2 | ./ver2 1 2 + echo -echo "$ echo Version 3 | ./ver3 1 2" -echo Version 3 | ./ver3 1 2 -echo + echo "$ echo Version 2 | ./ver2 1 2 3" + echo Version 2 | ./ver2 1 2 3 + echo +fi -echo "$ echo Version 3 | ./ver3 1 2 3" -echo Version 3 | ./ver3 1 2 3 +if [[ -e "./ver3" ]]; then + echo "$ echo Version 3 | ./ver3" + echo Version 3 | ./ver3 + echo + + echo "$ echo Version 3 | ./ver3 1" + echo Version 3 | ./ver3 1 + echo + + echo "$ echo Version 3 | ./ver3 1 2" + echo Version 3 | ./ver3 1 2 + echo + + echo "$ echo Version 3 | ./ver3 1 2 3" + echo Version 3 | ./ver3 1 2 3 +fi