From: Alex B. <a.b...@ma...> - 2010-02-23 23:21:16
|
Hi David, Thanks for the bug report. How about this: const char * Exception::basename( const char *s ) const { #ifndef WIN32 char *slashPos = strrchr( s, '/' ); #else char *slashPos = strrchr( s, '\\' ); #endif if ( slashPos == NULL ) return s; // no slash found else return slashPos+1; }; Will this work? On my system the filenames always have slashes so I can't test, but I've checked this version into svn -- let me know if you have any problems. Alex On Wed, 24 Feb 2010, David Lobato wrote: > Hi, > > I'm a developer in the Robotics Research Group at URJC [1]. We are > currently using gearbox in our software. > I think I've found a bug in exceptions.cpp: > > const char * > Exception::basename( const char *s ) const > { > #ifndef WIN32 > return strrchr( s, '/' )+1; > #else > return strrchr( s, '\\' )+1; > #endif > }; > > std::string > Exception::toMessageString( const char *file, const char *line, const > std::string &message ) const > { > std::string msg = "\n *** ERROR("; > // not to confuse our local basename() with gbxutilacfr::basename() > msg += this->basename(file); > msg += ":"; > msg += line; > msg += "): " + message; > return msg; > } > > > In basename it is supposed that s contains a "/" or "\\" for WIN32, but > this is not true always so strrchr returns NULL+1 in this cases. > In our system gcc compiles files with absolute paths, so __FILE__ is > substituted with a file name without any slash, making my programs SEGFAULT > whenever an exception is thrown. > > The bug could be solved easily checking the return of strrchr. > > Thanks, > David. > > > [1] http://jderobot.org/index.php/Main_Page |