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.
This commit is contained in:
Cody Boone Ferguson committed 2023-03-26 08:44:29 -07:00
1 parent 5873c7cedc
commit ce6af463e3
2 files changed
+3 -5

No files matched your search

+2 -4
View File
@@ -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:
+1 -1
View File
@@ -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<=