Fix infinite loop in 1992/vern
If one entered input < 0 || > 077 (octal) the program would enter an infinite loop that flooded the screen, forcing the user to terminate the program. The problem was that scanf(3) (with "%o %o" specifier string) was in a loop checking for return value of 2 (this was not a problem because scanf(3) does not return until all the specifiers are processed or I suppose some error occurs) and not checking the values. Instead it just checked a function on the numbers. This fix involves using scanf(3) with the specifier "%4s %4s" and then using strtol(3) with base 8 and then checking for < 0 || > 077 (using "%o %o" will not work). The game now functions as expected without flooding the terminal if invalid input is given. The judges' remarks about the range has been kept in as it's still invalid it just won't flood the screen.
This commit is contained in:
1 parent
c5a1123ab6
commit
fa80f73859
5 files changed
+24
-21
No files matched your search
@@ -946,22 +946,6 @@ it can 'rub your nose in defeat', as the author puts it. You will have to exit
|
||||
it yourself through ctrl-c or killing it in some other fashion.
|
||||
|
||||
|
||||
### STATUS: known bug - please help us fix
|
||||
|
||||
If one enters a number out of range, that is < 00 or > 77, the program will
|
||||
enter an infinite loop, flooding the screen.
|
||||
|
||||
You are welcome to try and fix this (mis)feature. It might help if you run the
|
||||
intermediate step in compilation like so:
|
||||
|
||||
```sh
|
||||
sed <vern.c 's/{ /(/g;s/} /)/g;s/; /#define /' | \
|
||||
sed 's/} /=/g;s/{ /i/g' >vern.tmp.c
|
||||
```
|
||||
|
||||
and look at `vern.tmp.c` instead, to give you an idea of what is going on.
|
||||
|
||||
|
||||
## 1992 westley
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
|
||||
Reference in new issue
Block a user