Undo two segfault fixes in 1991/dds - INABIAF
I noticed that I unfortunately fixed two segfaults that should not have been fixed: if the input file cannot be opened for reading or the output file cannot be opened for writing this program will crash. Changed both dds.c and dds.alt.c (which I added to work with clang). The original fix that allows this entry to work at all (segfaulted always) remains in both versions. Updated README.md and bugs.md. In bugs.md I also added a note that the compiled code uses gets() not fgets() - whatever it might be worth.
This commit is contained in:
1 parent
f48e546b13
commit
b5dc413e57
4 files changed
+52
-27
No files matched your search
+24
-17
@@ -20,31 +20,38 @@ make all
|
||||
./a.out
|
||||
```
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed some segfaults in
|
||||
this entry as well as making it so `a` (was `a.out`, see below) can be generated
|
||||
(as in the program did not work, at least with clang). The alternative code,
|
||||
described below, is what is needed for clang. Reading it might be instructive
|
||||
even if you have gcc.
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault that
|
||||
prevented this entry from working at all and made an alternate version
|
||||
that works with `clang`. The alternate code, described below, is what is needed
|
||||
for clang. Reading it might be instructive even if you have gcc.
|
||||
|
||||
The first segfault which was always triggered was due to the code `*q>'
|
||||
'&&(*q)--;`. This seems odd at first glance but it's pointing to `s` which was
|
||||
read-only memory as a `char *s`. It's now a `char s[]`. The second and third
|
||||
segfaults were caused if a file was not specified (or it the one specified did
|
||||
not exist or couldn't be opened for some reason) and if the output file could
|
||||
not be opened for writing.
|
||||
The segfault which was always triggered was due to the code `*q>' '&&(*q)--;`.
|
||||
This seems odd at first glance but it's pointing to `s` which was read-only
|
||||
memory as a `char *s`. It's now a `char s[]`.
|
||||
|
||||
Thank you Cody for your assistance!
|
||||
|
||||
### INABIAF - it's not a bug it's a feature! :-)
|
||||
|
||||
Please note that if the BASIC file cannot be opened for reading or the output
|
||||
file cannot be opened for writing then this program will crash. These crashes
|
||||
are a mild nuisance but are considered a feature not a bug. We challenge you to
|
||||
fix it for learning if you wish. See also [bugs.md](/bugs.md).
|
||||
|
||||
## Try:
|
||||
|
||||
With gcc, make and run as follows:
|
||||
|
||||
make dds
|
||||
|
||||
```sh
|
||||
make dds
|
||||
```
|
||||
|
||||
For example, the author suggests trying:
|
||||
|
||||
./dds LANDER.BAS
|
||||
./a.out
|
||||
|
||||
```sh
|
||||
./dds LANDER.BAS
|
||||
./a.out
|
||||
```
|
||||
|
||||
### Alternative code:
|
||||
|
||||
@@ -55,7 +62,7 @@ not messing with the `s` string which is quite complicated. For all Cody knows
|
||||
even changing the length could break functionality and indeed the length would
|
||||
have to be longer for this to work with clang.
|
||||
|
||||
How does it work? The code, which you will see in `dds.c`, `return system(q-6);`
|
||||
How does it work? The code, which you will see in [dds.c](dds.c), `return system(q-6);`
|
||||
equates to `return system("cc a.c");` but clang by default, at least in macOS,
|
||||
has default -Werror and there were some warnings. This means that the
|
||||
compilation failed with clang. In particular it would fail (at least with
|
||||
|
||||
+5
-5
@@ -10,8 +10,8 @@ R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
|
||||
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
|
||||
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";int k;char R[4][99]
|
||||
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
|
||||
[1],"r"),*o=fopen(q-3,"w");if(!i||!o)return 1;for(p=s;;p++)switch(*p++){B'M':
|
||||
Q(k=fgetc(i))!=EOF&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return
|
||||
system("make a");}*r=0 B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);
|
||||
p--B'C':k=0;Q k<*p-'0')(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G
|
||||
B'G':k= *p;G:p=s;while(*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
|
||||
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system("make a");}*r=0
|
||||
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
|
||||
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
|
||||
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
+5
-5
@@ -10,8 +10,8 @@ R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
|
||||
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
|
||||
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";int k;char R[4][99]
|
||||
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
|
||||
[1],"r"),*o=fopen(q-3,"w");if(!i||!o)return 1;for(p=s;;p++)switch(*p++){B'M':
|
||||
Q(k=fgetc(i))!=EOF&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return
|
||||
system(q-6);}*r=0 B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);
|
||||
p--B'C':k=0;Q k<*p-'0')(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G
|
||||
B'G':k= *p;G:p=s;while(*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
|
||||
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system(q-6);}*r=0
|
||||
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
|
||||
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
|
||||
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
Reference in new issue
Block a user