Merge pull request #262 from xexyl/1994-shapiro-eof
Fix EOF == -1 assumption in 1994/shapiro
This commit is contained in:
4 files changed
+17
-89
No files matched your search
+15
-11
@@ -10,17 +10,21 @@ USA
|
||||
|
||||
make all
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) pointed out a potential
|
||||
bug on systems where `EOF != -1`. The problem is that `getc()` and the related
|
||||
functions do not return `-1` on EOF or error but rather `EOF` but the program
|
||||
assumes `-1` (conversely when using the `getopt()` functions one should not
|
||||
check for EOF but -1 as the functions return -1 not EOF but the standard does
|
||||
not require `EOF` to be -1, just a negative number. However changing it to check
|
||||
for `!=EOF` caused a problem due to the clever encoding of the code. See
|
||||
[bugs.md](/bugs.md) for more details if you wish to try and fix this (Cody is
|
||||
here and there working on it along with other things and will change this
|
||||
message when it's fixed assuming it's feasible).
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a bug on systems
|
||||
where `EOF != -1`. The problem is that `getc()` and the related functions do not
|
||||
return `-1` on EOF or error but rather `EOF`. However `EOF` is not required to be
|
||||
`-1` but merely an int < 0 and this program assumed that `getc()` will return
|
||||
`-1` on EOF or error, not `EOF`. On systems where `EOF != -1` it could be a
|
||||
problem. For the same reason one should not use `EOF` for the `getopt()`
|
||||
functions as they return `-1` when all options are parsed (for details on the
|
||||
definition of `EOF` see `7.21 Input/output<stdio.h>` subsection 1 of the
|
||||
standard). An interesting problem occurred where changing the `-1` to `EOF`
|
||||
caused both `warning: illegal character encoding in string literal` and `error:
|
||||
source file is not valid UTF-8`. But since `EOF` is simply an int < 0 and making
|
||||
the loop condition check that the return value is >= 0 does not cause a
|
||||
compilation error and it functions correctly it will address the systems where
|
||||
`EOF != -1` just as if it checked for `!= EOF`. Thank you Cody for your
|
||||
assistance!
|
||||
|
||||
## To run:
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
/*T*/,"r");for (;( L/*KPUOWOWMUQ
|
||||
LLOLMPULWLWL WLW LWLWLWLWLWLW
|
||||
LWLWLULVOXP LLV LLLOLMPULOL
|
||||
MMNP*/=getc (J) )!= -1;L/*
|
||||
MMNP*/=getc (J) )>= 0;L/*
|
||||
OLWLRMMQUL VOX PLLVLLLMQO
|
||||
PMPYPXPNP MQL LVLLLWPSP
|
||||
XPOQNQOPMQ LLV LTj*/>='J'
|
||||
|
||||
@@ -13,7 +13,7 @@ This is a very simple program:
|
||||
5. FILE *J;
|
||||
6. J=fopen(__FILE__,"r");
|
||||
7. for(;
|
||||
8. (L=getc(J))!=EOF;
|
||||
8. (L=getc(J))>=0;
|
||||
9. L>='J'&&L<='J'+15 &&
|
||||
10. ((M=!M)?K=L:putchar(K-'J'|(L-'J'<<4)))
|
||||
11. );
|
||||
|
||||
Reference in new issue
Block a user