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:
Cody Boone Ferguson committed 2023-11-19 04:36:49 -08:00
1 parent c5a1123ab6
commit fa80f73859
5 files changed
+24 -21

No files matched your search

+3 -2
View File
@@ -40,7 +40,8 @@ include ../../var.mk
#
CSILENCE= -Wno-bitwise-conditional-parentheses -Wno-dangling-else -Wno-error \
-Wno-implicit-function-declaration -Wno-parentheses -Wno-pedantic \
-Wno-return-type -Wno-shift-op-parentheses -Wno-deprecated-non-prototype
-Wno-return-type -Wno-shift-op-parentheses -Wno-deprecated-non-prototype \
-Wno-implicit-int
# Common C compiler warning flags
#
@@ -137,7 +138,7 @@ ${PROG}: ${PROG}.tmp.c
${PROG}.tmp.c: ${PROG}.c
${RM} -f $@
${SED} <${PROG}.c 's/{ /(/g;s/} /)/g;s/; /#define /' | \
${SED} 's/} /=/g;s/{ /i/g' >$@
${SED} 's/} /=/g;s/{ /i/g;s/| /ii/g' >$@
# alternative executable
#
-1
View File
@@ -10,7 +10,6 @@ make all
The current status of this entry is:
```
STATUS: known bug - please help us fix
STATUS: INABIAF - please **DO NOT** fix
```
+5 -1
View File
@@ -12,6 +12,7 @@
; b else
; u while
; B if
char ii[5],jj[5];
U v,w,Y} -1,W,J,p,F,o} f,M,N,K,X,YY,_,P[f],s{ } ;
typedef U{ *L} { } ;
L q[f];
@@ -174,10 +175,13 @@ V{ ; ; } {
y{ } ;
o} f;
do{
ii[0]='\0';
jj[0]='\0';
i=j=0;
H"\n%d %d %d %s ",X,T,C{ } ,s{ } ?"!":">"} ;
fflush{ stdout} ;
}
u{ scanf{ "%o%o",&{ ,&j} !} 2||I{ { ,j,1} } ;
u{ scanf{ "%4s%4s",| ,jj} !} 2||(i=strtol(ii,NULL,8))<0||i>077||(j=strtol(jj,NULL,8))<0||j>077||I{ { ,j,1} } ;
O{ { ,j} ;
y{ } ;
X} 0;