[LLVMbugs] [Bug 17489] New: False positive with containers & loop initialized value, container excluding assumptions with empty() with size()

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 6 15:44:34 PDT 2013


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

            Bug ID: 17489
           Summary: False positive with containers & loop initialized
                    value, container excluding assumptions with empty()
                    with size()
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: artur at ebasoft.com.pl
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

For this code below analyzer assumes !empty() and size()==0 as a possible case
clang version 3.4 (191810)


#include <iostream>
#include <vector>

struct foo_t{ int value; void prt(){ std::cout << "Hello, world!"<< value <<
std::endl;}};
using foo_list_t =std::vector<foo_t>;

void func( foo_list_t & foo_list )
  {
  if( !foo_list.empty() )
    {
    foo_t * first_foo = nullptr;
    for( size_t i=0; i<foo_list.size(); ++i)
      {
      if( i == 0 )
        first_foo = &foo_list[i];
        std::cout << ".";
      }
    first_foo->prt();
    }
  }
int main(int argc, char **argv)
{
    foo_list_t foo_list{ {0},{1},{2}};
    func(foo_list);
    return 0;
}

-----------------------------------------------
9      if( !foo_list.empty() )
2
←Taking true branch→
10        {
11        foo_t * first_foo = nullptr;
3
←'first_foo' initialized to a null pointer value
→
12        for( size_t i=0; i<foo_list.size(); ++i)
4
←Loop condition is false. Execution continues on line 18
→
13          {
14          if( i == 0 )
15            first_foo = &foo_list[i];
16            std::cout << ".";
17          }
18        first_foo->prt();
5
←Called C++ object pointer is null
19        }

-- 
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/20131006/c7c57ca5/attachment.html>


More information about the llvm-bugs mailing list