[LLVMbugs] [Bug 17102] New: Clang should warn when retaining c_str() from temporary string

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 4 15:12:27 PDT 2013


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

            Bug ID: 17102
           Summary: Clang should warn when retaining c_str() from
                    temporary string
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: Matthew.Arsenault at amd.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Many times I have had to fix use after frees caused by people saving the
pointer from a temporary string's c_str(). The lifetime of the string is only
the assignment to foo expression, so any uses after are invalid. It would be
helpful to warn when a temporary string is used this way.


std::string returnsString()
{
    return "arstarstarstarstarst";
}

int main()
{
    const char* foo = returnsString().c_str();
    printf("This is a use after free %s\n", foo);
    return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130904/785186fb/attachment.html>


More information about the llvm-bugs mailing list