[LLVMbugs] [Bug 11281] New: False positive for interation of counter with addition and multiplication of self

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 31 14:42:05 PDT 2011


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

             Bug #: 11281
           Summary: False positive for interation of counter with addition
                    and multiplication of self
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: brent.gulanowski at nulayer.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following code is from the leveldb project.

bool ConsumeDecimalNumber(Slice* in, uint64_t* val) {
  uint64_t v = 0;
  int digits = 0;
  while (!in->empty()) {
    char c = (*in)[0];
    if (c >= '0' && c <= '9') {
      ++digits;
      const int delta = (c - '0');
      static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
      if (v > kMaxUint64/10 ||
          (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
        // Overflow
        return false;
      }
      v = (v * 10) + delta;
      in->remove_prefix(1);
    } else {
      break;
    }
  }
  *val = v;
  return (digits > 0);
}


When using Analyze in Xcode, the following result is reported:

Analyze leveldb/util/logging.cc
    cd /Users/bgulanowski/Dev/Nulayer/NULevelDB
    setenv LANG en_US.US-ASCII
    setenv PATH
"/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/usr/bin/clang -x c++ -arch i386 -fmessage-length=0
-fdiagnostics-print-source-range-info -fdiagnostics-show-category=id
-fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -O0
-Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable
-Wunused-value -Wno-shorten-64-to-32 -Wc++0x-extensions -DDEBUG=1 -isysroot
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk
-fexceptions -fasm-blocks -mmacosx-version-min=10.6 -gdwarf-2
-Wno-sign-conversion -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 -iquote
/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/leveldb-generated-files.hmap
-I/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/leveldb-own-target-headers.hmap
-I/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/leveldb-all-target-headers.hmap
-iquote
/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/leveldb-project-headers.hmap
-iquote/Users/bgulanowski/Dev/Nulayer/NULevelDB/leveldb/include
-iquote/Users/bgulanowski/Dev/Nulayer/NULevelDB/leveldb
-I/Users/Shared/bgulanowski/Developer/Products/Debug-iphonesimulator/include
-I/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/DerivedSources/i386
-I/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/DerivedSources
-F/Users/Shared/bgulanowski/Developer/Products/Debug-iphonesimulator
-DOS_MACOSX -DLEVELDB_PLATFORM_POSIX -MMD -MT dependencies -MF
/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/StaticAnalyzer/normal/i386/logging.d
--analyze /Users/bgulanowski/Dev/Nulayer/NULevelDB/leveldb/util/logging.cc -o
/Users/Shared/bgulanowski/Developer/Intermediates/NULevelDB.build/Debug-iphonesimulator/leveldb.build/StaticAnalyzer/normal/i386/logging.plist

/Users/bgulanowski/Dev/Nulayer/NULevelDB/leveldb/util/logging.cc:71:22:{71:20-71:21}:
warning: The left operand to '*' is always 0
       v = delta + (v * 10);
                    ~ ^
/Users/bgulanowski/Dev/Nulayer/NULevelDB/leveldb/util/logging.cc:71:17:{71:19-71:27}:
warning: The right operand to '+' is always 0
       v = delta + (v * 10);
                 ^ ~~~~~~~~
2 warnings generated.


If you wish, you may download NULevelDB from github and run the Analyzer on
that.

As far as I can tell, delta is > 0 if c is > '0', so v is *not* always zero.

Thanks for your awesome work, you people are amazing.

Cheers,
Brent Gulanowski

This is for version 3.0 of clang. At least, that's what it output in Terminal.
I am using Xcode 4.2 for Lion.

-- 
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.



More information about the llvm-bugs mailing list