diff --git a/1990/theorem/README.md b/1990/theorem/README.md index 2a985d1c3..95f9e08fa 100644 --- a/1990/theorem/README.md +++ b/1990/theorem/README.md @@ -12,8 +12,13 @@ make all [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed some segfaults -under modern (and in some cases earlier) systems with this entry. Thank you Cody -for your assistance! +under modern (and in some cases earlier) systems with this entry. He also fixed +a segfault if not enough args are used. 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'. To +make this easier for users Cody also kindly fixed this problem. Finally he +changed this program to use `fgets()` not `gets()` to make it safer. 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 @@ -22,7 +27,7 @@ initially. Thank you Yusuke! ## To run: - ./mariano expression x1 x2 h y1 + ./theorem expression x1 x2 h y1 where: @@ -35,7 +40,7 @@ where: ## Try: - ./mariano y 0 1 0.1 1 + ./theorem y 0 1 0.1 1 @@ -44,7 +49,7 @@ where: The program's source implements four functions, all from the same source file! -When you compile mariano.c as is and run with 5 args, it numerically +When you compile theorem.c as is and run with 5 args, it numerically solves the equation y'=f(x,y), with a step size of h, over the interval x=[x1,x2], with the initial condition of y(x1)=y1. @@ -59,14 +64,14 @@ left to right. (i.e., parenthesis aren't supported). Try running the program with the following args: - ./mariano y 0 1 0.1 1 - ./mariano 1/x 1 2 0.1 0 - ./mariano 'x^2/y+x' 0 1 0.1 6 + ./theorem y 0 1 0.1 1 + ./theorem 1/x 1 2 0.1 0 + ./theorem 'x^2/y+x' 0 1 0.1 6 But wait, there is more! You also get, free of charge, a reversing filter! Try: - ./mariano -r 0 0 0 0 < mariano.c > sorter.c + ./theorem -r 0 0 0 0 < theorem.c > sorter.c Still not impressed? The author throws in for free, a sort program! Try: @@ -78,12 +83,12 @@ This program is safe for home use as well. The author has included a safety feature in case you misplace the original program source: - ./sorter -r 0 0 0 0 < sorter.c > mariano_bkp.c + ./sorter -r 0 0 0 0 < sorter.c > theorem_bkp.c And finally, as a special offer to users of this entry, the author provides a Fibonacci sequence generator! Try: - ./sorter 0 0 0 0 < mariano.c > fibonacci.c + ./sorter 0 0 0 0 < theorem.c > fibonacci.c cc fibonacci.c -o fibonacci ./fibonacci 1 1 ./fibonacci 2 1 @@ -95,10 +100,6 @@ When this program was first shown at the 1990 Summer Usenix conference, it received a standing ovation; a first for a contest 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'. To make this easier for users Cody -Boone Ferguson kindly fixed this problem. ## Author's comments diff --git a/1990/theorem/theorem.c b/1990/theorem/theorem.c index 7512d69fe..cd2c619aa 100644 --- a/1990/theorem/theorem.c +++ b/1990/theorem/theorem.c @@ -24,6 +24,7 @@ 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;}} main(A,a)int A;char*a[]; o o +if (a[1]==NULL||a[2]==NULL||a[3]==NULL||a[4]==NULL||a[5]==NULL) return 1; if(!strcmp(*++a,"-r"))S(); D=atof(*++a); T=atof(*++a); @@ -78,12 +79,12 @@ return O; for(j=0;j