[OpenIndiana-discuss] Solaris C++ feof(): are we doing things differently?

Reginald Beardsley pulaskite at yahoo.com
Sun Oct 27 13:10:06 UTC 2013


Linux allows programmers to do things they shouldn't like call fclose() on a null pointer.  As a consequence, software developed on Linux can be rife with subtle errors which show up on Solaris.

I was going to download FEBio, but the licensing makes that a bit of a nuisance as I'm just an individual w/ no academic affiliation and no need for a commercial license.

To fix you need to look at the instances where XMLReader::GetChar() is called to see how they expect to handle EOF.  m_nline should be just a count of the number of lines of input.  If it's a storage buffer there's a problem.   The wile is just to skip over multiple newlines. You should probably bring this up w/ the FEBio developers as it looks like a nascent bug to me.


An example of normal usage of feof(0 would be:

 while( (c=fgetc(fp)) && !feof(fp) ){
   putc(c);
}

which copies character from fp to stdout until it hits an EOF on fp and then terminates. This is a minor variant of cat(1).

feof(fp)==1 is only an error if the code is expecting input and it's missing.  For example if it's read "key = \n" instead of "key = val\n" in a parser.


Reg


________________________________
 From: Bryan N Iotti <ironsides.medvet at runbox.com>
To: DiscussionOpenIndiana <openindiana-discuss at openindiana.org> 
Sent: 
Subject: [OpenIndiana-discuss] Solaris C++ feof(): are we doing things	differently?
 

Hi all,

got a little question for you that's been driving me crazy.

I'm trying to compile the FEBio finite element analysis software on OI hipster 151a8.

Studio 12.3 CC compilation is not working at all, with hundreds of errors, so for now I turned to g++.

g++ compiles fine with -g -m64 (I want the debug flags for now) and runs. However when I try to open a file from the verification suite it sends a SIGCABRT and terminates with "terminate called after throwing an instance of 'XMLReader::EndOfFile'
terminate called recursively".

I tracked it down in the code to the following function:

char XMLReader::GetChar()
{
    char ch;
    while ((ch=fgetc(m_fp))=='\n') ++m_nline;
    if (feof(m_fp)) throw EndOfFile();
    return ch;
}

m_fp is a file pointer. m_line is the current line, used as temp storage.
Setting a breakpoint at the feof() line allows the program to run until the end of the file, in which case it exits after trying to read past the end of the file (to my best guess and watching the gdb variables change).

Funny thing is, I have an old Enterprise 250 with a 400 Mhz UltraSPARC II and running Martin's OpenSXCE that runs it fine, no errors.

So I'd like to know:
- Are we supposed to use feof() differently from Linux?
- Are we using it differently on x86 and SPARC?
- Are we doing things differently from OpenSXCE?
- Any clues as to how I could rewrite the above in order for it to work?

Thank you all for any help you can provide on this matter.

   Bryan


-- 
Bryan N Iotti

+39 366 3708436
ironsides.medvet at runbox.com
_______________________________________________
OpenIndiana-discuss mailing list
OpenIndiana-discuss at openindiana.org
http://openindiana.org/mailman/listinfo/openindiana-discuss


More information about the OpenIndiana-discuss mailing list