From cf2ec74b17f3037a401afdedbb9af1dbcaa33fc7 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 20 Mar 2023 08:42:46 -0700 Subject: [PATCH] Fix 1996/westley It always segfaulted (though with the correct input it still showed the right results) and when argc == 1 it showed an environmental variable. The body of the for loop can now be empty (or so it appears). I put the original in westley.alt.c because it has some interesting techniques in which he wrote about (which I preserved in the README.md file). I also put in the original code because I'm not entirely sure if the for loop really can be empty in all cases. Certainly it can be in the scripts provided but I don't know if there is a valid invocation that would need it (but in any case it would always segfault with that loop body). Updated 1996/westley/.gitignore (added westley.alt) and the Makefile so that make alt will build westley.alt. Formatting fixes in README.md. --- 1996/westley/.gitignore | 1 + 1996/westley/Makefile | 4 ++-- 1996/westley/README.md | 31 ++++++++++++++++++++++++++----- 1996/westley/westley.alt.c | 1 + 1996/westley/westley.c | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 1996/westley/westley.alt.c diff --git a/1996/westley/.gitignore b/1996/westley/.gitignore index 2a0c890f9..0c08f64e6 100644 --- a/1996/westley/.gitignore +++ b/1996/westley/.gitignore @@ -1 +1,2 @@ westley +westley.alt diff --git a/1996/westley/Makefile b/1996/westley/Makefile index 92a7192ed..f73463f0a 100644 --- a/1996/westley/Makefile +++ b/1996/westley/Makefile @@ -167,8 +167,8 @@ OBJ= ${PROG}.o DATA= clock1 clock2 clock3 TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= westley.alt.o +ALT_TARGET= westley.alt ################# diff --git a/1996/westley/README.md b/1996/westley/README.md index 3c14411c6..775a0779d 100644 --- a/1996/westley/README.md +++ b/1996/westley/README.md @@ -11,26 +11,47 @@ make all -### To run + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in +this entry as well as it displaying environmental variables if argc == 1. +Although the scripts showed correct output these also segfaulted but with the +fix they no longer do. Now if argc < 5 (argv[4] is referenced) it will not do +anything and it will not segfault either (this was caused by the body of the +for() loop which is now empty (it doesn't appear to be needed at all). Note that +this does make some of the author's explanations / portability notes no longer +valid but we have kept them there for the interested. The original is in +[westley.alt.c](westley.alt.c). Thank you Cody for your assistance! + + +## To run: sh ./clock1 -## Judges' comments + +## Try: + + + sh ./clock2 Also try: + + + sh ./clock2 - sh ./clock2 And for a good time, try: - sh ./clock3 + + sh ./clock3 + +## Judges' comments: Time and time again, Brian Westley seems to come up with a winner! We are amazed at how much is being done with only one relatively short line. We think you will as well if you take the time to understand it. -## Author's comments +## Author's comments: This 1-line program allows various analog ASCII clocks to print out the time; the ASCII clock is built from diff --git a/1996/westley/westley.alt.c b/1996/westley/westley.alt.c new file mode 100644 index 000000000..00f7ec364 --- /dev/null +++ b/1996/westley/westley.alt.c @@ -0,0 +1 @@ +main(h,m)char**m;{for(time(*m);h/=2;)m[4][m[h][h[(int*)localtime(*m)]]]=m[3][h];puts(m[4]);} diff --git a/1996/westley/westley.c b/1996/westley/westley.c index 00f7ec364..46d2475b5 100644 --- a/1996/westley/westley.c +++ b/1996/westley/westley.c @@ -1 +1 @@ -main(h,m)char**m;{for(time(*m);h/=2;)m[4][m[h][h[(int*)localtime(*m)]]]=m[3][h];puts(m[4]);} +main(h,m)int h;char**m;{if(h>4){for(time(*m);h/=2;);puts(m[4]);}}