|
|
Re: Corrected bug in StringHelper::endsWith on CVS HEAD: msg#00025
apache.logging.log4cxx.user
|
Subject: |
Re: Corrected bug in StringHelper::endsWith on CVS HEAD |
It is checked the row above this row, I quote: "if (suffix.length()
<= s.length()) {"
And I should be a bit more clear on anopther point to. This is my
suggestion for solution, I have not commited this code, since I'm not a
member of the project.
And I post it here since I'm not a member of
log4cxx-dev@xxxxxxxxxxxxxxxxxx. either. If I find more things I
want to correct, I will consider to find some other way.
/Björn Carlsson
VersionSupport.com
Stoyan Damov wrote:
If suffix.length() is bigger than s.length()
you'll get std::out_of_range exception, because s.length() -
suffix.length() will yield a *very* big value.
(but I haven't looked at the source code to see
whether the arguments are being checked by the caller, so sorry for my
comment, if that's the case)
Cheers,
Stoyan
Both
bool StringHelper::endsWith(const std::string& s, const
std::string& suffix)
and
bool StringHelper::endsWith(const std::wstring& s, const
std::wstring& suffix)
should be like this:
return s.compare(s.length()
- suffix.length(), suffix.length(), suffix)
== 0;
and not
return suffix.compare(s.length()
- suffix.length(), suffix.length(), s)
== 0;
--
|
| |