[LLVMbugs] [Bug 10461] New: std::string should *not* use C string functions like strcmp, wcscmp

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jul 23 22:31:22 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10461

           Summary: std::string should *not* use C string functions like
                    strcmp, wcscmp
           Product: libc++
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: oneill+llvmbugs at cs.hmc.edu
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6920)
 --> (http://llvm.org/bugs/attachment.cgi?id=6920)
stringcheck.cpp — show problems with std::string

std::string strings are allowed to contain NUL ('\0'), C strings by definition
cannot. Thus you should be very careful about where you use C string functions.

% clang++ -g -o stringcheck stringcheck.cpp
% ./stringcheck
% clang++ -g -stdlib=libc++ -o stringcheck stringcheck.cpp
% ./stringcheck
Assertion failed: (x < y), function main, file stringcheck.cpp, line 9.
Abort

(What's interesting, perhaps, is that it's right for char_traits<char> (that
code uses memcmp) — maybe the other code ought to be using that?)

This issue is repeated with wcscmp vs wmemcmp for wchar_t.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list