[LLVMbugs] [Bug 13807] New: Warn when memset size/value args may be swapped

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Sep 10 09:34:44 PDT 2012


             Bug #: 13807
           Summary: Warn when memset size/value args may be swapped
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: dblaikie at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang doesn't warn when the user inverts the 2nd and 3rd argument to memset:

int i;
memset(&i, sizeof(i), 0); // user intends memset(&i, 0, sizeof(i))

If the user wrote the literal 0 as the memset length that's clearly wrong
(assuming no macros got in the way - ie: the source location "FileID" of both
the literal 0 and the word 'memset' are the same (if I understand
SourceLocations correctly that statement should make sense)) & they probably
meant to invert the arguments. We could potentially use the value of the second
parameter as a further hint, but I'm not sure how/when it would be a good
signal (honestly I expect the vast majority of memsets to be setting to zero,
but I could be wrong -perhaps someone does have a need to set the value of
memory to the size of some time using memset...)

[I should probably look at PR9977 for some code related to memset warnings as a
starting point to adding this warning]

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