Synopsis: Problems with signed/unsigned char in various fread_ functions. January 97 From: erwin@pip.dknet.dk To: MERC/Envy Mailing List Subject: fread_*: Envy/ROM/SSM - int vs char and EOF handling The fread_string() in Envy/ROM as well as the one accompaning SSM has a minor flaw: char *ptr; [...] switch ( *ptr = getc( fp ) ) Since getc() returns an integer, -1 upon EOF, the EOF case below will not work properly on machines/compilers where char is unsigned (not sure what these are, but your MUD will probably have to run one one tomorrow :) - and will also trigger when the character read in happens to be 0xFF (it *shouldn't* usually apper in text files, but.. :) Change 'char c' also in that function into 'int c' and add something like: c = getc(fp); *ptr = c; switch (c) ... temp_fread_string(), fread_word, fread_to_eol are also affected. The Envy fread_to_eol will enter an endless loop if it encounters EOF before EOL, as it keeps reading from the file until it encounters an '\n' or '\r'. fread_number is partially affected: if an EOF is encountered in the middle of the string, it will exit with a "bad format" message which is perhaps a bit cryptic. This flaw does not show if you have a proper area file: but if something goes wrong under saving, or you are trying to load a area or other file generated by a human, you might encounter seemingly unexplainable errors. PS: I'm not sure if this has been discussed before, but I fell victim to this myself today :) ============================================================================== Erwin Andreasen Viby J, Denmark Computer Science Student at Aarhus Business erwin@pip.dknet.dk College ==============================================================================