diff --git a/1990/cmills/README.md b/1990/cmills/README.md index 7aab5822b..1ffc1057d 100644 --- a/1990/cmills/README.md +++ b/1990/cmills/README.md @@ -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. diff --git a/1990/tbr/README.md b/1990/tbr/README.md index 9724d5aee..9224eb261 100644 --- a/1990/tbr/README.md +++ b/1990/tbr/README.md @@ -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. diff --git a/1992/adrian/README.md b/1992/adrian/README.md index f1ad0b52c..9bc7b26f9 100644 --- a/1992/adrian/README.md +++ b/1992/adrian/README.md @@ -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. diff --git a/1992/gson/README.md b/1992/gson/README.md index bc78dd775..fe90038ae 100644 --- a/1992/gson/README.md +++ b/1992/gson/README.md @@ -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 diff --git a/1992/lush/README.md b/1992/lush/README.md index 287987eab..8b93a22ff 100644 --- a/1992/lush/README.md +++ b/1992/lush/README.md @@ -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