From 5873c7cedc9bd3014b1bcfc8a6d00fb2705525c1 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 26 Mar 2023 08:40:32 -0700 Subject: [PATCH 1/2] Fix fix on 1990/dds + make it use fgets() The Makefile had -include stdio.h which made it fail to compile under macOS (mismatch type of fopen()). I removed the prototype in the code. I also made it use fgets() instead of gets() to make it safer. --- 1990/dds/LANDER.BAS | 2 +- 1990/dds/README.md | 9 ++++++--- 1990/dds/dds.c | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/1990/dds/LANDER.BAS b/1990/dds/LANDER.BAS index 1b515ba6f..5953e5835 100644 --- a/1990/dds/LANDER.BAS +++ b/1990/dds/LANDER.BAS @@ -1,6 +1,6 @@ 10 REM Lunar Lander 20 REM By Diomidis Spinellis -30 PRINT "You aboard the Lunar Lander about to leave the spacecraft." +30 PRINT "You board the Lunar Lander about to leave the spacecraft." 60 GOSUB 4000 70 GOSUB 1000 80 GOSUB 2000 diff --git a/1990/dds/README.md b/1990/dds/README.md index 446737380..ae62f9cbc 100644 --- a/1990/dds/README.md +++ b/1990/dds/README.md @@ -14,14 +14,15 @@ [Yusuke Endoh](/winners.html#Yusuke_Endoh) fixed this for modern systems. Thank you Yusuke! +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) removed the erroneous +prototype to `fopen()` and made this use `fgets()` instead of `gets()` to make +it safer. Thank you Cody for your assistance! + ### To run ./dds -NOTE: this entry uses `gets()` so you might get a warning when compiling and -running this entry. - ### Try: Give the following lines as input: @@ -31,6 +32,8 @@ Give the following lines as input: NOTE: this is case sensitive. +NOTE: this program will likely segfault if you specify a file that cannot be +opened. ## Judges' comments: diff --git a/1990/dds/dds.c b/1990/dds/dds.c index 3cac21f3d..a7585e669 100644 --- a/1990/dds/dds.c +++ b/1990/dds/dds.c @@ -7,12 +7,12 @@ #define _ return #define R 999 typedef char*A;int*C,E[R],L[R],M[R],P[R],l,i,j;char B[R],F[2];A m[12*R],malloc -(),p,q,x,y,z,s,d,f,fopen();A Q(s,o)A s,o;{for(x=s;*x;x++){for(y=x,z=o;*z&&*y== -*z;y++)z++;if(z>o&&!*z)_ x;}_ 0;}main(){m[11*R]="E";while(puts("Ok"),gets(B) -)switch(*B){X'R':C=E;l=1;for(i=0;io&&!*z)_ x;}_ 0;}main(){m[11*R]="E";while(puts("Ok"),fgets(B,R,stdin), +B[strlen(B)-1]='\0',1)switch(*B){X'R':C=E;l=1;for(i=0;i",'#');U("<=",'$');U(">=",'!');}d=B;while(*F=*s){*s=='"'&&j ++;if(j&1||!Q(" \t",F))*d++=*s;s++;}*d--=j=0;if(B[1]!='=')switch(*B){X'E':l=-1 -X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?gets(p=B),P[*d]=S():(*(q=Q(B,"TH"))=0,p +X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?fgets(p=B,R,stdin),P[*d]=S():(*(q=Q(B,"TH"))=0,p =B+2,S()&&(p=q+4,l=S()-1))X'P':B[5]=='"'?*d=0,puts(B+6):(p=B+5,printf("%d\n",S ()))X'G':p=B+4,B[2]=='S'&&(*C++=l,p++),l=S()-1 X'F':*(q=Q(B,"TO"))=0;p=B+5;P[i =B[3]]=S();p=q+2;M[i]=S();L[i]=l X'N':++P[*d]<=M[*d]&&(l=L[*d]);}else p=B+2,P[ From ce6af463e3ef3bce2500c01b904863cc4fc0a559 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 26 Mar 2023 08:44:29 -0700 Subject: [PATCH 2/2] Fix segfault in 1990/dds In all versions the program would segfault if the file could not be opened as it would write/close the NULL FILE *. Now it doesn't act on the file unless f != NULL. If it is it just does the usual of writing 'Ok' to stdout. --- 1990/dds/README.md | 6 ++---- 1990/dds/dds.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/1990/dds/README.md b/1990/dds/README.md index ae62f9cbc..6805a6d0f 100644 --- a/1990/dds/README.md +++ b/1990/dds/README.md @@ -16,7 +16,8 @@ you Yusuke! [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) removed the erroneous prototype to `fopen()` and made this use `fgets()` instead of `gets()` to make -it safer. Thank you Cody for your assistance! +it safer. He also fixed a segfault in the case that the file cannot be loaded. +Thank you Cody for your assistance! ### To run @@ -32,9 +33,6 @@ Give the following lines as input: NOTE: this is case sensitive. -NOTE: this program will likely segfault if you specify a file that cannot be -opened. - ## Judges' comments: diff --git a/1990/dds/dds.c b/1990/dds/dds.c index a7585e669..b615faeb5 100644 --- a/1990/dds/dds.c +++ b/1990/dds/dds.c @@ -17,7 +17,7 @@ X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?fgets(p=B,R,stdin),P[*d]=S():(*(q=Q(B,"TH ()))X'G':p=B+4,B[2]=='S'&&(*C++=l,p++),l=S()-1 X'F':*(q=Q(B,"TO"))=0;p=B+5;P[i =B[3]]=S();p=q+2;M[i]=S();L[i]=l X'N':++P[*d]<=M[*d]&&(l=L[*d]);}else p=B+2,P[ *B]=S();l++;}X'L':N printf(I)X'N':N(free(m[i]),0),m[i]=0 X'B':_ 0 t('S',5,"w",N -fprintf(f,I))t('O',4,"r",while(fgets(B,R,f))(*Q(B,"\n")=0,G()))X 0:default:G() +f&&fprintf(f,I))t('O',4,"r",while(f&&fgets(B,R,f))(*Q(B,"\n")=0,G()))X 0:default:G() ;}_ 0;}G(){l=atoi(B);m[l]&&(free(m[l]),0);(p=Q(B," "))?strcpy(m[l]=malloc(strlen(p )),p+1):(m[l]=0,0);}O(S,J,'=',==,'#',!=)O(J,K,'<',<,'>',>)O(K,V,'$',<=,'!',>=) O(V,W,'+',+,'-',-)O(W,Y,'*',*,'/',/)Y(){int o;_*p=='-'?p++,-Y():*p>='0'&&*p<=