[llvm-bugs] [Bug 25993] New: scan-build: false positive w/memset return

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 1 19:44:02 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=25993

            Bug ID: 25993
           Summary: scan-build: false positive w/memset return
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: vapier at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

scan-build does not seem to understand the relationship between the first arg
and the return value.  from POSIX:
  http://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html
  void *memset(void *s, int c, size_t n);
  RETURN VALUE
    The memset() function shall return s;

so when you have code like:
  #include <stdio.h>
  #include <string.h>
  int main(int argc, char *argv[])
  {
      char *s = memset(malloc(10), 0, 10);
      strcpy(s, "abc");
      puts(s);
      return 0;
  }

scan-build wrongly reports:
test.c:5:2: warning: Potential memory leak
        char *s = memset(malloc(10), 0, 10);
        ^~~~~~~
1 warning generated.
scan-build: 1 bug found.

-- 
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/20160102/9312a0d6/attachment.html>


More information about the llvm-bugs mailing list