Merge pull request #328 from xexyl/1992-lush

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-04-08 00:13:50 -07:00
commit cfab0e5700
5 files changed
+22 -18

No files matched your search

+2 -1
View File
@@ -23,7 +23,8 @@ work in modern systems (it resulted in a bus error otherwise). Thank you Yusuke
for your assistance!
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this safer by
using `fgets()` instead of `gets()`. Thank you Cody!
using `fgets()` instead of `gets()`. This avoids a potentially alarming warning
at linking or runtime. Thank you Cody for your assistance!
The original bug fixed version is in [cmills.alt.c](cmills.alt.c), described in
the `Alternate code` section.
+3 -2
View File
@@ -23,8 +23,9 @@ make all
modern compilers; `exit(3)` returns void but the function was used in a binary
expression so this wouldn't even compile. Cody also changed the code to use
`fgets()` instead of `gets()` so one would not get a warning about the use of
`gets()` at execution which was interspersed with the output. Thank you Cody for
your assistance!
`gets()` at linking time or execution, the latter case causing confusing output
due to the warning being interspersed with the program's output. Thank you Cody
for your assistance!
For the original version with `gets()` see the alternate code section below.
+11 -10
View File
@@ -14,16 +14,17 @@ make all
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the location
that it used `gets()` to be `fgets()` instead to make it safer. One might think
that simply changing the gets() to fgets() (with stdin) would work but it did
not because `fgets()` stores the newline and `gets()` does not. The code was
relying on not having this newline. With `fgets()` the code `if(A(Y)) puts(Y);`
ended up printing an extra line which made the generation of some files (like
`adhead.c`) fail to compile (`gets()` does not store the newline but `fgets()`
does). Why? There was a blank line after a `\` at the end of the first line of a
macro definition! Thus the code now first trims off the last character of the
buffer read to get the same correct functionality but in a safe way. Thank you
Cody for your assistance!
that it used `gets()` to be `fgets()` instead to make it safer and to prevent
any warnings during linking or runtime. One might think that simply changing the
gets() to fgets() (with stdin) would work but it did not because `fgets()`
stores the newline and `gets()` does not. The code was relying on not having
this newline. With `fgets()` the code `if(A(Y)) puts(Y);` ended up printing an
extra line which made the generation of some files (like `adhead.c`) fail to
compile (`gets()` does not store the newline but `fgets()` does). Why? There was
a blank line after a `\` at the end of the first line of a macro definition!
Thus the code now first trims off the last character of the buffer read to get
the same correct functionality but in a safe way. Thank you Cody for your
assistance!
For the original version [adrian.alt.c](adrian.alt.c) see the `Alternate code` section below.
+5 -4
View File
@@ -16,13 +16,14 @@
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the buffer size
in such a way that gets() should be safe (theoretically) as it comes from the
command line. Ideally `fgets()` would be used but this is a more problematic.
command line (though it can also read input from stdin after starting the
program). Ideally `fgets()` would be used but this is a more problematic.
Previously it had a buffer size of 256 which could easily overflow. In this
entry `gets()` is used in a more complicated way: first `m` is set to `*++p` in
a for loop where `p` is argv. Later `m` is set to point to `h` which was of size
\256. `gets()` is called as `m = gets(m)`) but trying to change it to use fgets()
proved more a problem. Since the input must come from the command line Cody
changed the buffer size to `ARG_MAX+1` which should be enough (again
\256. `gets()` is called as `m = gets(m)`) but trying to change it to use
fgets() proved more a problem. Since the input must come from the command line
Cody changed the buffer size to `ARG_MAX+1` which should be enough (again
theoretically) especially since the command expects redirecting a dictionary
file as part of the command line. This also makes it possible for longer strings
to be read (in case the `gets()` was not used in a loop). Thank you Cody for
+1 -1
View File
@@ -28,7 +28,7 @@ code` section below.
### Alternate code:
The original source (fixed to work with gcc) which uses gets() try:
For the original source (fixed to work with gcc) which uses gets() try:
```sh
make alt