<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - scan-build false positive: not realizing that "> unsigned" implies "> 0"?"
   href="https://bugs.llvm.org/show_bug.cgi?id=39767">39767</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>scan-build false positive: not realizing that "> unsigned" implies "> 0"?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cperciva@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21147" name="attach_21147" title="test case">attachment 21147</a> <a href="attachment.cgi?id=21147&action=edit" title="test case">[details]</a></span>
test case

The attached source file (scan-build-fp.c) has two assertions; the first
asserts that an expression is > a size_t variable, while the second is hidden
behind #ifdef SCAN_BUILD_IS_STUPID and asserts that the same expression is > 0.

It should be trivial to deduce that anything which is greater than an unsigned
value must be greater than zero, but scan-build fails to do this and yields a
false positive warning unless the > 0 condition is separately asserted:

$ scan-build70 cc -c scan-build-fp.c 
scan-build: Using '/usr/local/llvm70/bin/clang-7' for static analysis
scan-build-fp.c:85:3: warning: Null pointer argument in call to memory copy
function
                memcpy((uint8_t *)(EA->buf) + bufpos, buf, nbytes);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2018-11-24-063313-4294-1' to examine
bug reports.

$ scan-build70 cc -c scan-build-fp.c -DSCAN_BUILD_IS_STUPID
scan-build: Using '/usr/local/llvm70/bin/clang-7' for static analysis
scan-build: Removing directory '/tmp/scan-build-2018-11-24-063309-4282-1'
because it contains no reports.
scan-build: No bugs found.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>