Re: [Cppunit-devel] questionable code @ TypeInfoHelper.cpp
Brought to you by:
blep
|
From: Duane M. <dua...@ma...> - 2002-04-18 15:12:26
|
--- At Thu, 18 Apr 2002 16:05:54 +0900, FUKUDA Fumiki wrote:
>Hi all,
>
>----- excerpt from src/cppunit/TypeInfoHelper.cpp -----
>std::string
>TypeInfoHelper::getClassName( const std::type_info &info )
>{
> static std::string classPrefix( "class " );
> std::string name( info.name() );
>
> bool has_class_prefix = 0 ==
>#if CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
> name.compare( classPrefix, 0, classPrefix.length() );
>#else
> name.compare( 0, classPrefix.length(), classPrefix );
>#endif
> return has_class_prefix ? name.substr( classPrefix.length() ) : name;
>}
>------------------
>
>if info.name().length() < classPrefix.length(), an exception should be
thrown.
>I think this method should return 'name' at this condition (as follows).
This is incorrect. string.compare() will not throw an exception under
these conditions. The minimum of classPrefix.length() and
info.name().length() will be compared. The code is fine.
...Duane
--
"If tyranny and oppression come to this land, it will be in the
guise of fighting a foreign enemy." - James Madison
|