[LLVMbugs] [Bug 9062] New: -Wuninitialized false positive

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jan 26 16:54:20 PST 2011


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

           Summary: -Wuninitialized false positive
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu


chrome code:

    bool found = false;
    const char *pair;

    for (unsigned i = 0; env[i]; i++) {
      pair = env[i];
      const char *const equals = strchr(pair, '=');
      if (!equals)
        continue;
      const unsigned keylen = equals - pair;
      if (keylen == j->first.size() &&
          memcmp(pair, j->first.data(), keylen) == 0) {
        found = true;
        break;
      }
    }

    // if found, we'll either be deleting or replacing this element.
    if (found) {
      count--;
      size -= strlen(pair) + 1;
      if (j->second.size())
        found = false;
    }



clang complains:


/Volumes/MacintoshHD2/src/chrome-git/src/base/process_util_posix.cc:378:11:
error: use of uninitialized variable 'pair' [-Wuninitialized]
    const char *pair;
          ^~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/base/process_util_posix.cc:396:22:
note: variable 'pair' is possibly uninitialized when used here
      size -= strlen(pair) + 1;
                     ^~~~
/Volumes/MacintoshHD2/src/chrome-git/src/base/process_util_posix.cc:378:21:
note: add initialization to silence this warning
    const char *pair;
                    ^
                     = 0
1 error generated.



…but the access happens only if |found| is true, and in that case the pointer
is always initialized.

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