[openbeos] Small bug (?) in String.cpp

  • From: "Niels Reedijk" <niels.reedijk@xxxxxxxxx>
  • To: "Haiku Mailinglist" <openbeos@xxxxxxxxxxxxx>
  • Date: Mon, 1 Jan 2007 14:27:16 +0000

Hi,

While working on the documentation of the BString class, I think I
found a small bug in FindLast(char, int offset).

That method doesn't check if the offset given is higher than the
Length(). While all the BString methods are generally boundary safe,
someone manipulating the string on their own might start messing in
memory that isn't theirs.

I included a small patch at the end of this message that might fix
this issue. Am I right on that this is a bug?

And in a similar note, can I remove all the doxygen comments from
String.cpp while I'm at it, I copied it all to string.dox and it makes
no sense to keep it in both places.

Niels

Index: String.cpp
===================================================================
--- String.cpp  (revision 19660)
+++ String.cpp  (working copy)
@@ -1304,7 +1304,7 @@
               return B_ERROR;

       const char *start = String();
-       const char *end = String() + beforeOffset;
+       const char *end = String() + min_clamp0(beforeOffset, Length());

       /* Scans the string backwards until we found the character, */
       /* or we reach the string's start */

Other related posts: