From 06a5665f5d1c86f89f8dc36a4fd5064cb70d44fa Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 5 Apr 2023 05:22:35 -0700 Subject: [PATCH] Make alt code for gets() / fgets() changes As both Landon and I have been wondering if changing entries to use fgets() is bordering on tampering with entries I decided to make the original (sometimes bug fixed) versions (using gets()) alt code. I had originally started to make the fgets() version of each entry the alt but since the fgets() versions can handle input better and since some also fixed bugs (see below) I decided to make the original version the alt code (this also is how it is for other entries). There were some exceptions here. If the change also fixed some crashes or other bugs outside of the gets() to fgets() conversion I did not bother to make an alt version. An example is 1992/dds. In some cases the alt code does have bug fixes in which case they were added. Updated the Makefiles and .gitignore files as well for the alt target and the new files (compiled and in the case of 1992/adrian additional source files in the Makefile alt rule). This should solve the problem observed by Landon and me. It wouldn't be a problem to change it so the alt version is the one that uses fgets() but I think that might be the wrong choice. In some entries I altogether avoided changing to fgets() say if the author notes it uses gets() (in one case even providing a version that uses fgets()). In some cases using fgets() introduces a bug so those are also not changed. As for 1990/tbr there's a strong reason for not having the fgets() version being the alt. In macOS in particular (in linux - or maybe gcc, not sure - it shows a warning at linker time) it will mess up the first line of output in a potentially confusing way. For instance: $ ./tbr.alt $ warning: this program uses gets(), which is unsafe. # nothing here, what to do? And that touches on another issue of making the alt version the one that uses gets(): the warnings that can be alarming during compilation, linking and (in the case of macOS) runtime. Not all entries should be or can be changed to fgets() but some can and it's warranted for these reasons. More will possibly happen in the future. --- 1987/wall/.gitignore | 1 + 1987/wall/Makefile | 4 +- 1987/wall/README.md | 40 +++++---- 1987/wall/wall.alt.c | 18 ++++ 1990/cmills/.gitignore | 1 + 1990/cmills/Makefile | 4 +- 1990/cmills/README.md | 35 +++++--- 1990/cmills/cmills.alt.c | 30 +++++++ 1990/tbr/README.md | 37 ++++---- 1992/adrian/.gitignore | 11 +++ 1992/adrian/Makefile | 23 ++++- 1992/adrian/README.md | 29 +++++- 1992/adrian/adrian.alt.c | 113 ++++++++++++++++++++++++ 1992/adrian/adrian.c | 2 +- 1992/gson/README.md | 12 +-- 1992/lush/Makefile | 4 +- 1992/lush/README.md | 26 ++++-- 1992/lush/lush.alt.c | 167 +++++++++++++++++++++++++++++++++++ 1993/schnitzi/README.md | 2 +- 1994/ldb/.gitignore | 1 + 1994/ldb/Makefile | 4 +- 1994/ldb/README.md | 33 +++++-- 1994/ldb/ldb.alt.c | 1 + 1994/schnitzi/.gitignore | 1 + 1994/schnitzi/Makefile | 4 +- 1994/schnitzi/README.md | 27 ++++-- 1994/schnitzi/schnitzi.alt.c | 52 +++++++++++ 2000/anderson/.gitignore | 1 + 2000/anderson/Makefile | 4 +- 2000/anderson/README.md | 13 +++ 2000/anderson/anderson.alt.c | 58 ++++++++++++ 31 files changed, 672 insertions(+), 86 deletions(-) create mode 100644 1987/wall/wall.alt.c create mode 100644 1990/cmills/cmills.alt.c create mode 100644 1992/adrian/adrian.alt.c create mode 100644 1992/lush/lush.alt.c create mode 100644 1994/ldb/ldb.alt.c create mode 100644 1994/schnitzi/schnitzi.alt.c create mode 100644 2000/anderson/anderson.alt.c diff --git a/1987/wall/.gitignore b/1987/wall/.gitignore index 8d40b1eda..8784710db 100644 --- a/1987/wall/.gitignore +++ b/1987/wall/.gitignore @@ -1 +1,2 @@ wall +wall.alt diff --git a/1987/wall/Makefile b/1987/wall/Makefile index 3edd2f5eb..1eaea9de5 100644 --- a/1987/wall/Makefile +++ b/1987/wall/Makefile @@ -115,8 +115,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1987/wall/README.md b/1987/wall/README.md index a5161bd65..f9c3ba1dd 100644 --- a/1987/wall/README.md +++ b/1987/wall/README.md @@ -7,27 +7,25 @@ Panorama City, CA 91402 USA ## To build: - make all +```sh +make all +``` -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this entry safer -by changing `gets()` to `fgets()`. Thank you Cody for your assistance! If you -wish for the original unsafe version you can make the following change: - - -signal())();char*V,cm,D['x'],M='\n',I;L(MV,V,(c+='d',ix))m(x){v) - +signal())();char*V,cm,D['x'],M='\n',I,*gets();L(MV,V,(c+='d',ix))m(x){v) - signal(X/'I',vi[x]);}d(x)char*x;{v)write(i,x,i);}L(MC,V,M+I)xv(){c>=i?m( - c/M/M+M):(d(&M),m(cm));}L(mi,V+cm,M)L(md,V,M)MM(){c=c*M%X;V-=cm;m(ix);} - -LXX(){fgets(D,'x',stdin)||(vi[iv])();c=atoi(D);while(c>=X){c-=X;d("m");}V="ivxlcdm" - +LXX(){gets(D)||(vi[iv])();c=atoi(D);while(c>=X){c-=X;d("m");}V="ivxlcdm" ## To run: +```sh +./wall +# enter some strings - ./wall - # enter some strings +./wall | some_command +# enter some strings +``` + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this safer by +using `fgets()` instead of `gets()`. The original source is in +[wall.alt.c](wall.alt.c) described below. Thank you Cody! - ./wall | some_command - # enter some strings ## Try: @@ -55,6 +53,18 @@ and enter some input like: 2^x quit # for the cat version +### Alternate code: + + +For the original version that uses `gets()` try: + + +```sh +make alt +``` + +Use `wall.alt` as you would `wall`. + ## Judges' comments: diff --git a/1987/wall/wall.alt.c b/1987/wall/wall.alt.c new file mode 100644 index 000000000..8ba1c5458 --- /dev/null +++ b/1987/wall/wall.alt.c @@ -0,0 +1,18 @@ +#define iv 4 +#define v ;(void +#define XI(xi)int xi[iv*'V']; +#define L(c,l,i)c(){d(l);m(i);} +#include +int*cc,c,i,ix='\t',exit(),X='\n'*'\d';XI(VI)XI(xi)extern(*vi[])(),(* +signal())();char*V,cm,D['x'],M='\n',I,*gets();L(MV,V,(c+='d',ix))m(x){v) +signal(X/'I',vi[x]);}d(x)char*x;{v)write(i,x,i);}L(MC,V,M+I)xv(){c>=i?m( +c/M/M+M):(d(&M),m(cm));}L(mi,V+cm,M)L(md,V,M)MM(){c=c*M%X;V-=cm;m(ix);} +LXX(){gets(D)||(vi[iv])();c=atoi(D);while(c>=X){c-=X;d("m");}V="ivxlcdm" ++iv;m(ix);}LV(){c-=c;while((i=cc[*D=getchar()])>-I)i?(c?(c>I;cc[-I]-=ix v)close(*VI);cc[M]-=M;}main(){ +(*vi)();for(;v)write(VI[I],V,M));}l(xl,lx)char*lx;{v)printf(lx,xl)v) +fflush(stdout);}L(xx,V+I,(c-=X/cm,ix))int(*vi[])()={ii,li,LXX,LV,exit,l, +d,l,d,xv,MM,md,MC,ml,MV,xx,xx,xx,xx,MV,mi}; diff --git a/1990/cmills/.gitignore b/1990/cmills/.gitignore index 931adc228..1bb1b86ab 100644 --- a/1990/cmills/.gitignore +++ b/1990/cmills/.gitignore @@ -1 +1,2 @@ cmills +cmills.alt diff --git a/1990/cmills/Makefile b/1990/cmills/Makefile index 491b4779d..03743d3a0 100644 --- a/1990/cmills/Makefile +++ b/1990/cmills/Makefile @@ -115,8 +115,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1990/cmills/README.md b/1990/cmills/README.md index 5d729eb31..7aab5822b 100644 --- a/1990/cmills/README.md +++ b/1990/cmills/README.md @@ -8,32 +8,43 @@ ## To build: - make all +```sh +make all +``` ## To run - ./cmills [starting_cash] +```sh +./cmills [starting_cash] +``` We used a patch from [Yusuke Endoh](/winners.html#Yusuke_Endoh) to get this to work in modern systems (it resulted in a bus error otherwise). Thank you Yusuke for your assistance! -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made the program safer -by using `fgets()` instead of `gets()`. Thank you Cody for your help in making -this safer! For the original code you can change the instances of: +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this safer by +using `fgets()` instead of `gets()`. Thank you Cody! - - !fgets(l,M,stdin) - -to: - - !gets(l) +The original bug fixed version is in [cmills.alt.c](cmills.alt.c), described in +the `Alternate code` section. ## Try: - ./cmills 5000 +```sh +./cmills 5000 +``` +### Alternate code: + +For the original version that uses `gets()` try: + + +```sh +make alt +``` + +Use `cmills.alt` as you would `cmills`. ## Judges' comments: diff --git a/1990/cmills/cmills.alt.c b/1990/cmills/cmills.alt.c new file mode 100644 index 000000000..8a9b25641 --- /dev/null +++ b/1990/cmills/cmills.alt.c @@ -0,0 +1,30 @@ +#include +#include +#define S(q)B(*e=0),q,p); +#define W(w)if((w)<22)v= -v;else v-=10;else +#define F for(r=d;r1;){if(r-d>N*3/4){B(8));F++r)*r=c[(r-d)%13];F)w= +*(g=d+rand()%N),*g= +*r,*r++=w;r=d;}for(;;){B(3),y);if(!gets(l)||(w=atoi(l))<1)exit(0);if(w&1||w>M||w>y)B(1),y=w/2&&u(5)&&(y+=(3*(h(0,1[q])==10)-1)*w/2);if(x==-21)goto +_;if(v==-21){y+=w/2;goto +_;}while(x>-17&&x<17)H(x,g)while((v==20||*p==-1[e])&&y>=w&&u(6)){y-=w;++s;for(g=e++;2[g]= +*g,g!=p;)--g;*g++= +*e;*g=' ';i:v=h(h(0,*p),*e++= +*r++);S(t)if(*p=='A'&&-1[e]!= +*p)goto +_;}if(f=y>=w&&u(7))y-=w,H(v,e)while(!f&&v<22&&u(4)){H(v,e)if(v<22)S(t)}_:x<0&&(x= +-x);v<0&&(v= +-v);if(v<22)if(v==x)j+=w*++f;else +if(x>21||v>x)j+=w*2*++f;if(s--){*e++=' ';*e++= +*p;*e=0;for(e=p;*e=2[e];)e++;goto +i;}y+=j;S(q)};} diff --git a/1990/tbr/README.md b/1990/tbr/README.md index da9ad5976..9724d5aee 100644 --- a/1990/tbr/README.md +++ b/1990/tbr/README.md @@ -15,7 +15,9 @@ ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work with modern compilers; `exit(3)` returns void but the function was used in a binary @@ -24,24 +26,14 @@ expression so this wouldn't even compile. Cody also changed the code to use `gets()` at execution which was interspersed with the output. Thank you Cody for your assistance! -For the original version with `gets()` see the alternative code section below. - -## Alternative code: - -If you wish to see the original source (fixed so it can compile) that uses -`gets()` instead of `fgets()` you can look at [tbr.alt.c](tbr.alt.c). To compile -it: - - make alt - -Use `./tbr.alt` instead of `./tbr` for this version. You'll likely get a warning -about the usage of `gets()`. - +For the original version with `gets()` see the alternate code section below. ## To run: - ./tbr - # enter some shell commands +```sh +./tbr +# enter some shell commands +``` NOTE: globs do not work with this entry. Why? @@ -61,6 +53,19 @@ or ctrl-c (or kill it from another terminal :-) ). What happens if you try using `cd -` to return to previous directory? What about `cd` with no args? +## Alternate code: + +If you wish to see the original source (fixed so it can compile) that uses +`gets()` instead of `fgets()` you can look at [tbr.alt.c](tbr.alt.c). To compile +it: + +```sh +make alt +``` + +Use `tbr.alt` as you would `tbr`. You'll likely get a warning about the usage of +`gets()` and with macOS it will mess up output of the first line. + ## Judges' comments: diff --git a/1992/adrian/.gitignore b/1992/adrian/.gitignore index d1f2f4681..b426c122e 100644 --- a/1992/adrian/.gitignore +++ b/1992/adrian/.gitignore @@ -10,3 +10,14 @@ adsleep.c adwc adwc.c adrian +adrian.alt +adbasename.alt +adbasename.alt.c +adecho.alt +adecho.alt.c +adhead.alt +adhead.alt.c +adsleep.alt +adsleep.alt.c +adwc.alt +adwc.alt.c diff --git a/1992/adrian/Makefile b/1992/adrian/Makefile index 74232495a..fe0a5e91c 100644 --- a/1992/adrian/Makefile +++ b/1992/adrian/Makefile @@ -118,8 +118,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -160,6 +160,25 @@ adgrep: ${PROG} # alternative executable # alt: data ${ALT_TARGET} + ${RM} -f ad.alt.temp adwc.alt.c adbasename.alt.c adecho.alt.c adhead.alt.c adsleep.alt.c + ${SED} '1s/\..*\./. wc ./' adrian.alt.c > ad.alt.temp + -./adrian.alt ad.alt.temp adwc.alt.c + ${CC} ${CFLAGS} -o adwc.alt adwc.alt.c + ${SED} '1s/\..*\./. basename ./' adrian.alt.c > ad.alt.temp + -./adrian.alt ad.alt.temp adbasename.alt.c + ${CC} ${CFLAGS} -o adbasename.alt adbasename.alt.c + ${SED} '1s/\..*\./. echo| ./' adrian.alt.c > ad.alt.temp + -./adrian.alt ad.alt.temp adecho.alt.c + ${CC} ${CFLAGS} -o adecho.alt adecho.alt.c + ${SED} '1s/\..*\./. head; ./' adrian.alt.c > ad.alt.temp + -./adrian.alt ad.alt.temp adhead.alt.c + ${CC} ${CFLAGS} -o adhead.alt adhead.alt.c + ${SED} '1s/\..*\./. sleep ./' adrian.alt.c > ad.alt.temp + -./adrian.alt ad.alt.temp adsleep.alt.c + ${CC} ${CFLAGS} -o adsleep.alt adsleep.alt.c + ${RM} -f ad.alt.temp + + @${TRUE} # data files diff --git a/1992/adrian/README.md b/1992/adrian/README.md index 8810622e8..f1ad0b52c 100644 --- a/1992/adrian/README.md +++ b/1992/adrian/README.md @@ -8,7 +8,9 @@ ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the location @@ -23,15 +25,34 @@ macro definition! Thus the code now first trims off the last character of the buffer read to get the same correct functionality but in a safe way. Thank you Cody for your assistance! - +For the original version [adrian.alt.c](adrian.alt.c) see the `Alternate code` section below. ## Try: - ./adrian adrian.grep.try < README.md +```sh +./adrian adrian.grep.try < README.md +``` For the slow minded, try: - ./adsleep 32767 +```sh +./adsleep 32767 +``` + +NOTE: if you do not specify an arg to the program it will segfault. + +### Alternate code: + +For the original version that uses `gets()` try: + + +```sh +make alt +``` + +Use `adrian.alt` as you would `adrian`. + + ## Judges' comments: diff --git a/1992/adrian/adrian.alt.c b/1992/adrian/adrian.alt.c new file mode 100644 index 000000000..5bd259728 --- /dev/null +++ b/1992/adrian/adrian.alt.c @@ -0,0 +1,113 @@ +/* . wc . */ +#include/* Wht majr flwchrt? */ +#include/* That mjr flwchrt! */ +#define P 257 +#define G 17 +#define z 8 +#define v(jr) jr +int W ,head; +#define S(W,b,f) strncpy(W,b,f),W[f]=0\ + + +char *wcs=" \t\n"; +struct{ char X[z+1]; + char f ; + int e ; + struct{ char g[z+1]; + int b ; + } w[ G]; + } o[ P]; +int L=0,j= -28; + + +void E(int i, int m,char*c) +{ + for(; i<43; i+=3) + putc("}|uutsrq`_^bji`[Zkediml[PO]a_M__]ISOYIRGTNR"[i]+i-9,stderr); + fprintf(stderr,"(%d): %s\n" ,m,c); + exit(1); +} + + + +int N(int m, char *t) +{ + int i ; + if (strlen ( + t)>z) t[z ]=0; + for(i= 0; i< L ; i++) if( + !strcmp (o[ i] . X + , t))return i; + if( L== P) + E(0, m, t); + S (o[ L] . X , t + ,z); + head; W = .1* head; + o[L ].f = !( strchr( t,']' )== 0 ); + o[L ++ ] . e = 0; + return L -1 ; } + +#define v(x ) + +int A(char *R) +{ + int c=0, i; + while(* R) { + i = -1; + while(j){ + if( ++ i==o[ c].e ) return 0; + if(o[ + c] .w[i ] .g[0 ] + =='.' ||strchr (o[ c].w[i] .g ,* R)){ + c= + o[ c ] .w[i].b; break;/* +main(int sl,char *j[]){ + sleep (~~~~~~~~atoi(j[1])) ;/* . sl + sl s l . sl + l l ] + sl */ } + } + R++; + } + return o[ c].f; +} + + + main(int wc,char *V[]){char Y[999],*s;FILE*W;int m=0,echo,jr,q,wcl=0,wcw=0,wcc=0; + v(s = V[1]; if (*V=strrchr(s,'/'))s=*V+1; if(( !strncmp( s + (jr=strlen(s)) - + (q=strlen(V[2]) ),V[2],q))&&jr!=q) s[jr-q] = 0; puts(s); ) + int e,p,C=0,Q ,basename; + W= fopen(wc>= 2 ? V[1] : "adgrep.c","rt"); +echo| m^ e| 5| (int) .8| echo| +wc |C ==o[o[C] .e] . +e| e==+p,p; s[o[C] .e ] +; +while( fgets(Y,998,W)) { wcc += strlen(Y); m++; + if( s = strtok(Y,wcs)) wcw++; + else continue ; + C= + basename= j +j+*"* . basename" + +j+*"* r ] " + N(m,s) ; +while( s = strtok(0,wcs)) { + if( o[ C ] . e == + G) E(1 ,m,o[C] .X) ; + S(o[C + ] .w[o[C ] .e].g,s, z); + Q= C ; + if(! ( s =strtok ( 0 ,wcs )))wcw -- + ,E( 2 , m, o[C] + . w[ o[ Q ] .e] . g ); + e + = o[C ] .w[o[C ] .e++ ] .b= N(m,s) + ; wcw += 2; } + 0&& + W && wcl++ + < 10 && printf((W,Y)); } + if(j+28) { { + ; } printf("%7u%7u%7u\n", wcl , wcw , wcc); } + while( gets(Y) ) if(A(Y)) puts(Y); + W, jr; } + +O(int wc,char**V) { +--wc && (printf("%s ",*++V), main(wc,V), 1) || printf("\n"); } + diff --git a/1992/adrian/adrian.c b/1992/adrian/adrian.c index 913f72940..ded8fdcc2 100644 --- a/1992/adrian/adrian.c +++ b/1992/adrian/adrian.c @@ -7,7 +7,7 @@ #define v(jr) jr int W ,head; #define S(W,b,f) strncpy(W,b,f),W[f]=0\ - + char *wcs=" \t\n"; struct{ char X[z+1]; char f ; diff --git a/1992/gson/README.md b/1992/gson/README.md index 666b6b38c..bc78dd775 100644 --- a/1992/gson/README.md +++ b/1992/gson/README.md @@ -17,12 +17,12 @@ [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the buffer size in such a way that gets() should be safe (theoretically) as it comes from the command line. Ideally `fgets()` would be used but this is a more problematic. -Previously it had a buffer size of 256 which could easily overflow. Now in this -entry `gets()` is used in a more complicated way. First `m` is set to `*++p` in -a for loop where `p` is argv and then later `m` is set to point to `h` which is -of size 256. `gets()` is called as `m = gets(m)`) but trying to change it to use -fgets() proved more a problem. Since the input must come from the command line -Cody changed the buffer size to `ARG_MAX+1` which should be enough (again +Previously it had a buffer size of 256 which could easily overflow. In this +entry `gets()` is used in a more complicated way: first `m` is set to `*++p` in +a for loop where `p` is argv. Later `m` is set to point to `h` which was of size +\256. `gets()` is called as `m = gets(m)`) but trying to change it to use fgets() +proved more a problem. Since the input must come from the command line Cody +changed the buffer size to `ARG_MAX+1` which should be enough (again theoretically) especially since the command expects redirecting a dictionary file as part of the command line. This also makes it possible for longer strings to be read (in case the `gets()` was not used in a loop). Thank you Cody for diff --git a/1992/lush/Makefile b/1992/lush/Makefile index 17210a790..a4002d851 100644 --- a/1992/lush/Makefile +++ b/1992/lush/Makefile @@ -112,8 +112,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1992/lush/README.md b/1992/lush/README.md index 23c3974cc..287987eab 100644 --- a/1992/lush/README.md +++ b/1992/lush/README.md @@ -15,11 +15,27 @@ [Yusuke Endoh](/winners.html#Yusuke_Endoh) supplied a patch which makes this -work with gcc. Thank you Yusuke! [Cody Boone -Ferguson](/winners.html#Cody_Boone_Ferguson) made it use `fgets()` instead of -`gets()` and also added the `runme.sh` script to demonstrate it (using make was -problematic). Cody notes that unfortunately this does not work with clang due to -different compiler messages. Thank you Cody! +work with gcc. Due to how it works (see Judges' comments below) this will not +work with clang. Thank you Yusuke! + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made it use `fgets()` +instead of `gets()` and also added the `runme.sh` script to demonstrate it +(using make was problematic). Cody notes that unfortunately this does not work +with clang due to different compiler messages. Thank you Cody! + +For the original entry see [lush.alt.c](lush.alt.c) described in the `Alternate +code` section below. + +### Alternate code: + +The original source (fixed to work with gcc) which uses gets() try: + +```sh +make alt +``` + +Use `lush.alt` as you would `lush`. + ## Judges' comments: diff --git a/1992/lush/lush.alt.c b/1992/lush/lush.alt.c new file mode 100644 index 000000000..c788ea0f0 --- /dev/null +++ b/1992/lush/lush.alt.c @@ -0,0 +1,167 @@ +#define f 000: + char + *s,* + t,v; + char + _ [ + 999] + ,x [ + 999] + ,*p= + x ; + char + *av[ + ]= { + "W", + "H", + "o", + "l", + "N", + "e", + " ", + "r", + "d", + ".", + "m", + "s", + "g", + "!", + "*", + "\n" + } ; + int + n= 0 + ;int + __ = + 0,i= + 000; + main + () { +#define f 001: +#define F 042: +#define f 100: + _[i-- +#define f 126: +#define f 132: +#define f 103: +#define f 202: +#define f 666: +#define f 77:: +#define f 101: + ]=0 +#define f 232: +#define f 151: + ;if( +#define f 256: + !i){ + puts + ("I" + "BM" + " S" + "UX" + );;; + ;;;} + ;for + ( ; + gets + (_); + ) { + for( +#define f 301: + t=_, +#define f 700: +#define f 999: + s=t, +#define f 77 : +#define f 300: + s=t; +#define f s=t; +#define f 123: +#define f 127: + *t&& + !(!( + *t < + '0' + ||*t + >'9' + )&&! + ((t[ + 1] ^ + ':') + &&(t + [1]^ + '.') + )) ; + t++) +#define f 137: +#define f 133: + ;if( +#define f 111: +#define f 220: + v^*t + &&*t + ){v= + *t;; + n=n* + 2+(1 + &*t) + ;__= + (__+ + 1)&3 + ; __ + ||(( + n<15 + &&(* + p= * + av[n + ] ), +#define f 2+2: + p++) + ,n=0 + );}} +#define f ==4: + ;*p= + '\0' + ;;;; +#define f puts + puts + (x); + s=t; +#define f s=5; + s=t; +#define f s=5: + s=t; +#define f 445: +#define f 113: +#define f 900: + s=t; +#define f n22: +#define f n40: + s=t; +#define f nn6: + s=t; +#define f nn1: +#define f 0:-- + s=t; +#define f 19:- +#define f x2:x + s=t; +#define f x1:x + s=t; +#define f y2:x +#define f y7:y + s=t; +#define f 1::: + s=t; +#define f @3:@ +#define f 10:0 +#define f x+1: + s=t; +#define f 2::: +#define f 3::: +#define x 7::: +#define y 3::: +#define z 990: +#define Z 47:: + ;;;} + diff --git a/1993/schnitzi/README.md b/1993/schnitzi/README.md index bd6f70349..49ae8ccc0 100644 --- a/1993/schnitzi/README.md +++ b/1993/schnitzi/README.md @@ -10,7 +10,7 @@ make all [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to not -segfault when no file is specified or the file cannot be opened for reading. he +segfault when no file is specified or the file cannot be opened for reading. He also made this use `fgets()` not `gets()` to make it safer. Thank you Cody for your assistance! diff --git a/1994/ldb/.gitignore b/1994/ldb/.gitignore index ee4dfc7fc..9fa76f9f8 100644 --- a/1994/ldb/.gitignore +++ b/1994/ldb/.gitignore @@ -1 +1,2 @@ ldb +ldb.alt diff --git a/1994/ldb/Makefile b/1994/ldb/Makefile index 1b8d8425f..d22b3e1b1 100644 --- a/1994/ldb/Makefile +++ b/1994/ldb/Makefile @@ -111,8 +111,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt # FORCE use of -trigraphs # diff --git a/1994/ldb/README.md b/1994/ldb/README.md index e247738cd..dffa8dc4a 100644 --- a/1994/ldb/README.md +++ b/1994/ldb/README.md @@ -8,7 +8,9 @@ USA ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this so it would compile and work with modern compilers. The problem was that `srand()` returns @@ -21,21 +23,38 @@ a line is greater than 231 in length if the program chooses that line it might print the first 231 characters or it might print (up to) the next 231 characters and so on. Thank you Cody for your assistance! +For the original fixed version [ldb.alt.c](ldb.alt.c) see below. + ## To run: - ./ldb < file +```sh +./ldb < file - some_command | ./ldb +some_command | ./ldb +``` ## Try: - ./ldb < /etc/passwd +```sh +./ldb < /etc/passwd - printf "The International Obfuscated C Code Contest\n - Best One-liner\n - by Laurion Burchall" | ./ldb +printf "The International Obfuscated C Code Contest\n + Best One-liner\n + by Laurion Burchall" | ./ldb +``` + +### Alternate code: + +For the original version fixed so that it will compile with modern compiles, +try: + +```sh +make alt +``` + +Use `ldb.alt` as you would `ldb`. ## Judges' comments: diff --git a/1994/ldb/ldb.alt.c b/1994/ldb/ldb.alt.c new file mode 100644 index 000000000..9e7c492bf --- /dev/null +++ b/1994/ldb/ldb.alt.c @@ -0,0 +1 @@ +int _,O,__??('}'??);main(){while(O?gets((rand()%O++?':':_)+__)||puts(&__??(_??))&_:(srand(time((O+++_))),0)||O);} diff --git a/1994/schnitzi/.gitignore b/1994/schnitzi/.gitignore index 563ae8705..83b4fdd34 100644 --- a/1994/schnitzi/.gitignore +++ b/1994/schnitzi/.gitignore @@ -1 +1,2 @@ schnitzi +schnitzi.alt diff --git a/1994/schnitzi/Makefile b/1994/schnitzi/Makefile index 407e1d96d..cf2666d21 100644 --- a/1994/schnitzi/Makefile +++ b/1994/schnitzi/Makefile @@ -112,8 +112,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1994/schnitzi/README.md b/1994/schnitzi/README.md index 2c3d1dfaa..a528218cb 100644 --- a/1994/schnitzi/README.md +++ b/1994/schnitzi/README.md @@ -8,11 +8,15 @@ USA ## To build: - make all +```sh +make all +``` ## To run: - ./schnitzi < textfile +```sh +./schnitzi < textfile +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) increased the buffer size from 100 to 10000. Changing it to use `fgets()` instead of `gets()` is more @@ -21,17 +25,30 @@ results in compiler errors and not only that but the gets() is still there in the generated output. Even changing the buffer size can result in compilation errors if not done correctly. The generated output also does not have a changed buffer size. Changing it to use fgets() can happen later, maybe, but bigger -files can now be parsed by the original code. An example is this Makefile. Cody +files can now be parsed by the original code. An example is the Makefile. Cody gave some tips on how this entry works, in order to make the entry use fgets() and compile successfully too, in the [bugs.md](/bugs.md) file. Thank you Cody! +For the original source file [schnitzi.alt.c](schnitzi.alt.c) see below. + ## Try: - ./schnitzi < /etc/motd - ./schnitzi < /etc/passwd +```sh +./schnitzi < /etc/motd +./schnitzi < /etc/passwd +``` +### Alternate code: + +For the original version with a smaller buffer try: + +```sh +make alt +``` + +Use `schnitzi.alt` as you would `schnitzi`. ## Judges' comments: diff --git a/1994/schnitzi/schnitzi.alt.c b/1994/schnitzi/schnitzi.alt.c new file mode 100644 index 000000000..45a5365e4 --- /dev/null +++ b/1994/schnitzi/schnitzi.alt.c @@ -0,0 +1,52 @@ +#include +int r=0,x,y=0, /* +nt / +c +lx /\ / \ /|\ /|\ +u, \/ \\/ \-/ \ / +dn ] +e= ||| /|\ /\ /\ = p p + 0 \/ \ / ||| \/ f f f r r +<, tw t s s i i +sy || /|\ /\ i eh e e c n n +t= /- \ / ||| n li l e a t t +d0 ||| t ll l {< k n f f +i, || /|\ /|\ (e s ( fr ( f ( ( +o _ ||\ \ / \-/ tu s( t usw o; i s ( " " +. || - / c [[ tg rv [th rx=f t " % \ +h mh111 de{l) +di (+'( d+% c n+ +> aa000 itte; > +il x+ n inc " "+ + / ir000[ns[nytyrrne<=)'y ? t [ + r ] : y; + u[++r ] = + ftell(stdin ) ; } + while ( n + < y ) + {for(x=0 ; x + + +char +*T="IeJKLMaYQCE]jbZRskc[SldU^V\\X\\|/_<[<:90!\"$434-./2>]s", +K[3][1000],*F,x,A,*M[2],*J,r[4],*g,N,Y,*Q,W,*k,q,D;X(){r [r +[r[3]=M[1-(x&1)][*r=W,1],2]=*Q+2,1]=x+1+Y,*g++=((((x& 7) +-1)>>1)-1)?*r:r[x>>3],(++x<*r)&&X();}E(){A||X(x=0,g =J +),x=7&(*T>>A*3),J[(x[F]-W-x)^A*7]=Q[x&3]^A*(*M)[2 +( +x&1)],g=J+((x[k]-W)^A*7)-A,g[1]=(*M)[*g=M[T+=A ,1 +][x&1],x&1],(A^=1)&&(E(),J+=W);}l(){E(--q&&l () +);}B(){*J&&B((D=*J,Q[2]= +97&&D<123&&(*r=0,*g++=D-95)||!(D-k[ 3] +)&&(*r=0,*g++=12)||D>k[3]&&D<=k[ 1] +-1&&(*r=0,*g++=D-47),J++));}j( ){ +putchar(A);}b(){(j(A=(*K)[D* W+ +r[2]*Y+x]),++x