Merge pull request #250 from xexyl/1994-ldb

Make 1994/ldb use fgets()
This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-04-02 16:23:27 -07:00
commit 153d7b4788
3 files changed
+32 -17

No files matched your search

+15 -15
View File
@@ -1,20 +1,20 @@
# Best One-liner: # Best One-liner:
Laurion Burchall Laurion Burchall
Brown University Brown University
Unit 4641 Unit 4641
Providence RI 02912-4641 Providence RI 02912-4641
USA USA
## To build: ## To build:
make all make all
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this so it would [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this so it would
compile and work with modern compilers. Thank you Cody for your assistance! compile and work with modern compilers. The problem was that `srand()` returns
void but it was used in a `||` expression. Thus the comma operator was needed.
NOTE: this entry uses `gets()` so you will likely get a warning on compilation Cody also changed the entry to use `fgets()` instead of `gets()` to make it
and/or execution of the program. safe for lines greater than 231 in length. Thank you Cody for your assistance!
## To run: ## To run:
@@ -23,7 +23,6 @@ and/or execution of the program.
some_command | ./ldb some_command | ./ldb
NOTE: input lines must be under 232 characters long.
## Try: ## Try:
@@ -33,14 +32,15 @@ NOTE: input lines must be under 232 characters long.
Best One-liner\n Best One-liner\n
by Laurion Burchall" | ./ldb by Laurion Burchall" | ./ldb
## Judges' comments ## Judges' comments:
Trigraphs are natural obfuscators. Most C-beautifiers become Trigraphs are natural obfuscators. Most C-beautifiers become C-uglifiers
C-uglifiers because they don't handle them correctly. because they don't handle them correctly.
Can you figure out how it prints a given random line from stdin? Can you figure out how it prints a given random line (or if the line is longer
than 231 characters, part of that line) from stdin?
## Author's comments ## Author's comments:
All input lines must be under 232 characters long. The compiling All input lines must be under 232 characters long. The compiling
platform should be ASCII based. platform should be ASCII based.
+1 -1
View File
@@ -1 +1 @@
int _,O,__??('}'??);main(){while(O?gets((rand()%O++?':':_)+__)||puts(&__??(_??))&_:(srand(time((O+++_))),0)||O);} int _,O,__??('}'??);main(){while(O?(fgets((rand()%O++?':':_)+__,232,stdin))||puts(&__??(_??))&_:(srand(time((O+++_))),0)||O);}
+16 -1
View File
@@ -453,7 +453,22 @@ this simply does not work with them. Can you help us?
# 1994 # 1994
## [1994/schnitzi](1994/schnitzi.c) ([README.md])(1994/schnitzi/README.md)) ## [1994/ldb](1994/ldb/ldb.c) ([README.md](1994/ldb/README.md))
## STATUS: known bug - please help us fix
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to compile
with modern systems (see the README.md file for what had to change) but the
entry also used `gets()`. This could overflow long lines. Cody changed it to
`fgets()` but this introduces another problem namely that newlines can be
printed if the line length < 231.
This seems like a worthy compromise but it would be ideal for it to never print
a newline unless that's the line itself (a blank line).
Cody will be looking at this later on.
## [1994/schnitzi](1994/schnitzi/schnitzi.c) ([README.md])(1994/schnitzi/README.md))
## STATUS: uses gets() - change to fgets() if possible ## STATUS: uses gets() - change to fgets() if possible
The original buffer size of this entry is 100 which is very easily overflowed The original buffer size of this entry is 100 which is very easily overflowed