BUG: Warning: fread_word encountered EOF

Posted by Kit DeKat on Sun 15 Jul 2001 02:22 AM — 5 posts, 19,131 views.

#0
I am currently running a Michael K Weis' Win32 port of ROM 2.4b4 which has OLC and color already implemented.
(http://home.att.net/~mkw/mudframe.html -> mkwMUD-src.zip)

This version is completely ported over to C++ (ie: includes .cpp files) and ready to compile out-of-the-box. All you have to do is make the player/god/... folders and define them within the code.

One problem though, once running, i can make a new character, play around and quit just fine. BUT when i go to load that character it gives me the following log and locks up... doesnt even exit cleanly.

write_to_descriptor: MOPP: 2048; Bytes written: 2048; Bytes written 115
Loading Xrythe.
[*****] BUG: Warning: fread_word_char() encountered EOF.
[*****] BUG: Fread_char: no match.

the "Loading ___." and "Fread_char: no match" tell me that the error is within the only call to fread_word() within fread_char() as it reads in the character file. There's no match because there is no case for EOF returned. With my own debugging logic i have followed the trace from:

load_char_obj(fp, name) ->
...
word = fread_word(fp);
if (!str_cmp( word, "PLAYER" )) fread_char (ch, fp);
...

fread_char(ch,fp) ->
...
for ( ; ; )
word = feof(fp) ? "End" : fread_word(fp);
...

fread_word(fp) ->
...
for( ; pword < word +MAX_INPUT_LENGTH; pword++) {
*pword* = getc(fp);
if( feof(fp) || (cEnd == ' ' ? isspace(*pword) : *pword == cEnd)) {
...
if( feof(fp) )
bug( Warning: fread_word() encountered EOF.", 0);
...

cant determine why fread_word() fails on player file and not anywhere else (ie: areas/... ). MKW even added the feof() check in fread_word() not found in original ROM stock, so he knew it was an issue but apparently he got around it.
#1
correction:
-- BUG: Warning: fread_word() encountered EOF.
not:
-- BUG: Warning: fread_word_char() encountered EOF.

constantly mix fread_char() and fread_word() up. :p
Australia Forum Administrator #2
For a start I would change fread_to_eol to allow for end of file, see changes in bold:



void fread_to_eol( FILE *fp )
{
    char c;

    do
    {
	c = getc( fp );
    }
    while ( c != '\n' && c != '\r' && c != EOF);

    do
    {
	c = getc( fp );
    }
    while ( c == '\n' || c == '\r' );

    ungetc( c, fp );
    return;
}



I'm not sure why, but I made the problem go away by commenting out two lines in fread_char:


// sprintf(buf,"Loading %s.",ch->name);
// log_string(buf);


It seems that somehow the logging is interfering with the file pointer for the read_word, but why, I don't know.
Australia Forum Administrator #3
After more tests I can't work out why it is going wrong, but I suggest you write to Michael K. Weise - after all, it is his code.
#4
Thank you.. it stopped the bug, but odd methods here..
log/eol affects EOF.. ill check into it further myself.
And i was thinking of contacting MKW but there are no recent posts for about a year or so.... *shrug*

thank you. --KDK