[cfe-commits] Fwd: [llvm-commits] bug in libc++'s std::string::find_first_not_of

David Blaikie dblaikie at gmail.com
Mon Dec 31 11:01:07 PST 2012


Moving to the appropriate list (cfe-commits) & adding Howard.


---------- Forwarded message ----------
From: Klaas de Vries <klaas at klaasgaaf.nl>
Date: Mon, Dec 31, 2012 at 6:06 AM
Subject: [llvm-commits] bug in libc++'s std::string::find_first_not_of
To: llvm-commits at cs.uiuc.edu


Hi,

It seems that the libc++ implementation of
std::string::find_first_not_of - specifically the one taking a single
character as its first argument - does not handle the case where the
string contains only the given character (i.e. where it should return
string::npos).

A simple program demonstrating this:

int main()
{
  string test("--");
  string::size_type i = test.find_first_not_of('-');
  cout << (i == string::npos ? "okay" : "not okay") << '\n';
}

The cause seems to be a typo in the for-loop in the implementation
where a check for the inequality will return true for the first
character beyond the tested string (a bad thing).

Attached is what I believe to be a fix, and an updated test case.

Regards,
Klaas de Vries


_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
A non-text attachment was scrubbed...
Name: find_first_not_of.diff
Type: text/x-patch
Size: 1196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121231/460790c2/attachment.bin>


More information about the cfe-commits mailing list