Merge pull request #328 from xexyl/1992-lush
This commit is contained in:
5 files changed
+22
-18
No files matched your search
@@ -23,7 +23,8 @@ work in modern systems (it resulted in a bus error otherwise). Thank you Yusuke
|
|||||||
for your assistance!
|
for your assistance!
|
||||||
|
|
||||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this safer by
|
[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 original bug fixed version is in [cmills.alt.c](cmills.alt.c), described in
|
||||||
the `Alternate code` section.
|
the `Alternate code` section.
|
||||||
|
|||||||
+3
-2
@@ -23,8 +23,9 @@ make all
|
|||||||
modern compilers; `exit(3)` returns void but the function was used in a binary
|
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
|
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
|
`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
|
`gets()` at linking time or execution, the latter case causing confusing output
|
||||||
your assistance!
|
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.
|
For the original version with `gets()` see the alternate code section below.
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -14,16 +14,17 @@ make all
|
|||||||
|
|
||||||
|
|
||||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the location
|
[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 it used `gets()` to be `fgets()` instead to make it safer and to prevent
|
||||||
that simply changing the gets() to fgets() (with stdin) would work but it did
|
any warnings during linking or runtime. One might think that simply changing the
|
||||||
not because `fgets()` stores the newline and `gets()` does not. The code was
|
gets() to fgets() (with stdin) would work but it did not because `fgets()`
|
||||||
relying on not having this newline. With `fgets()` the code `if(A(Y)) puts(Y);`
|
stores the newline and `gets()` does not. The code was relying on not having
|
||||||
ended up printing an extra line which made the generation of some files (like
|
this newline. With `fgets()` the code `if(A(Y)) puts(Y);` ended up printing an
|
||||||
`adhead.c`) fail to compile (`gets()` does not store the newline but `fgets()`
|
extra line which made the generation of some files (like `adhead.c`) fail to
|
||||||
does). Why? There was a blank line after a `\` at the end of the first line of a
|
compile (`gets()` does not store the newline but `fgets()` does). Why? There was
|
||||||
macro definition! Thus the code now first trims off the last character of the
|
a blank line after a `\` at the end of the first line of a macro definition!
|
||||||
buffer read to get the same correct functionality but in a safe way. Thank you
|
Thus the code now first trims off the last character of the buffer read to get
|
||||||
Cody for your assistance!
|
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.
|
For the original version [adrian.alt.c](adrian.alt.c) see the `Alternate code` section below.
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -16,13 +16,14 @@
|
|||||||
|
|
||||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the buffer size
|
[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
|
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
|
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
|
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
|
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()
|
\256. `gets()` is called as `m = gets(m)`) but trying to change it to use
|
||||||
proved more a problem. Since the input must come from the command line Cody
|
fgets() proved more a problem. Since the input must come from the command line
|
||||||
changed the buffer size to `ARG_MAX+1` which should be enough (again
|
Cody changed the buffer size to `ARG_MAX+1` which should be enough (again
|
||||||
theoretically) especially since the command expects redirecting a dictionary
|
theoretically) especially since the command expects redirecting a dictionary
|
||||||
file as part of the command line. This also makes it possible for longer strings
|
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
|
to be read (in case the `gets()` was not used in a loop). Thank you Cody for
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ code` section below.
|
|||||||
|
|
||||||
### Alternate code:
|
### 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
|
```sh
|
||||||
make alt
|
make alt
|
||||||
|
|||||||
Reference in new issue
Block a user