diff --git a/1990/theorem/.gitignore b/1990/theorem/.gitignore index 47cb1bda8..12683bf7d 100644 --- a/1990/theorem/.gitignore +++ b/1990/theorem/.gitignore @@ -3,3 +3,5 @@ fibonacci.c mariano sorter sorter.c +theorem_bkp +theorem_bkp.c diff --git a/1990/theorem/README.md b/1990/theorem/README.md index d85a4675f..7353b46b2 100644 --- a/1990/theorem/README.md +++ b/1990/theorem/README.md @@ -11,13 +11,19 @@ USA make all -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed some segfaults -under modern (and in some cases earlier) systems with this entry. Originally we -noted that the 4 trailing args '0 0 0 0' were required on systems that dump core -when NULL is dereferenced but this problem showed itself in modern systems even -with the 4 '0 0 0 0'. Finally he changed this program to use `fgets()` not -`gets()` to make it safer and to prevent a warning about `gets()` at linking or -runtime. Thank you Cody for your assistance! +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed some bugs that +impacted the usability of this program including some segfaults under modern +systems (and possibly in some cases earlier systems) with this entry. +Originally we noted that the 4 trailing args '0 0 0 0' were required on systems +that dump core when NULL is dereferenced but this problem showed itself in +modern systems even with the 4 '0 0 0 0'. He also fixed the code so that the +generated `fibonacci.c` actually works; before it just printed `0` over and over +again (since it did not work anyway a segfault prevention was added here). He +also some array addressing (some of which might not be strictly necessary but as +he was testing the `fibonacci.c` bug he ended up changing it anyway). Finally he +changed this program to use `fgets()` not `gets()` to make it safer and to +prevent a warning about `gets()` at linking or runtime. Thank you Cody for your +assistance! [Yusuke Endoh](/winners.html#Yusuke_Endoh) pointed out that `atof` nowadays needs `#include ` which was used in order to get this to work diff --git a/1990/theorem/theorem.c b/1990/theorem/theorem.c index db1d0de8b..a6d30ebcd 100644 --- a/1990/theorem/theorem.c +++ b/1990/theorem/theorem.c @@ -21,7 +21,7 @@ if(R=='/')*g/=u; if(R=='^')P(g,*g,u); C w(g,R,u)float*g,u;char R; -/**/{int b,f;A=atoi(++a);b=atoi(++a);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}} +/**/{int b,f;if(A>2){A=atoi(a[1]);b=atoi(a[2]);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}} main(A,a)int A;char*a[]; o o if(!strcmp(*++a,"-r"))S(); @@ -46,14 +46,14 @@ W=D=1; ; while(W!=1) o o -strcpy(j+m,v); +strcpy(j[m],v); o if((j-=W)<=W)break; -strcpy(j+m,m+j-W); +strcpy(j[m],m[j-W]); C -while(strcmp(m+j-W,v)>0) +while(strcmp(m[j-W],v)>0) j=i; -strcpy(v,i+m); +strcpy(v,i[m]); C for(i=(W/=3)-1;++i