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

             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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to