Hi chaoswong,

I've just checked the code and docs on open() and it looks like a positive
return value is valid, a negative one is an error.  I've read one
description of the return type as greater than 0 being valid, and another
with any positive value being valid.  Not sure yet which is the official
version.  Negative return type is definatly the error case though so
checked for < 0 is appropriate, whether <= 0 is appropriate I'm not clear
yet.

Another aspect that looks certain is that the if (fd) close(fd) looks to be
inappropriate, instead I believe this line can be removed.

Robert.


On 23 July 2013 06:45, ChaosWong <[email protected]> wrote:

> hi, everyone:
>
> i develop osg application under windows. when i was loading a .shp file,
> my application was crashed. after i tracked, i found i miss a .bdf file,
> and code was crashed at red line:
>
> XBaseParser::XBaseParser(const std::string fileName):
>     _valid(false)
> {
>     int fd = 0;
>     if (fileName.empty() == false)
>     {
> #ifdef WIN32
>         if( (fd = open( fileName.c_str(), O_RDONLY | O_BINARY )) <= 0 )
> #else
>         if( (fd = ::open( fileName.c_str(), O_RDONLY )) <= 0 )
> #endif
>         {
>             perror( fileName.c_str() );
>             if (fd) close( fd );
>             return;
>         }
>     }
>
>     _valid = parse(fd);
> }
>
> I looked for "open" function's description, i found 
> this<http://linux.die.net/man/3/open>(linux)
> and 
> this<http://msdn.microsoft.com/en-us/library/z0kc8e3z%28v=vs.71%29.aspx>(windows),
> so i think this is a BUG.
> code should be like this:
>
> XBaseParser::XBaseParser(const std::string fileName):
>     _valid(false)
> {
>     int fd = 0;
>     if (fileName.empty() == false)
>     {
> #ifdef WIN32
>         if( (fd = open( fileName.c_str(), O_RDONLY | O_BINARY )) == 0 )
> #else
>         if( (fd = ::open( fileName.c_str(), O_RDONLY )) == 0 )
> #endif
>         {
>             perror( fileName.c_str() );
>             return;
>         }
>     }
>
>     _valid = parse(fd);
> }
>
> chaoswong
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to