[llvm-bugs] [Bug 27674] New: Multiple if / else if checks for NULL result in incorrect reporting of NULL dereference in final else

via llvm-bugs llvm-bugs at lists.llvm.org
Sat May 7 01:25:18 PDT 2016


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

            Bug ID: 27674
           Summary: Multiple if / else if checks for NULL result in
                    incorrect reporting of NULL dereference in final else
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: mark.rogers at powermapper.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

$ clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

Reproduction code:

class Buffer
{
    void* m_pBuffer;
    size_t m_size;

    bool Equal( const Buffer& rhs)
    {
        if( !m_pBuffer && rhs.m_pBuffer )
        {
            // m_pBuffer is null
            return false;
        }
        else if( m_pBuffer && !rhs.m_pBuffer )
        {
            // rhs.m_pBuffer is null
            return false;
        }
        else
        {
            // neither argument is null but analyzer warns:
            // Null pointer argument in call to memory comparison functions
            int cmp = memcmp( m_pBuffer, rhs.m_pBuffer, std::min( m_size,
rhs.m_size ) );
            return cmp == 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/20160507/4b5aa87d/attachment.html>


More information about the llvm-bugs mailing list