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

            Bug ID: 24037
           Summary: false positive, -Wsign-conversion, it is known that
                    signed value is positive
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Example code:

#include <string>

void f(int x, std::string s) {
    if (x >= 0)
      s[x] = 'x'; // <- warning about x
}

Clang writes this false positive:

signconv.cpp:21:9: warning: implicit conversion changes signedness: 'int' to
'size_type' (aka 'unsigned long') [-Wsign-conversion]
      s[x] = 'x';
      ~ ^

it is obvious that x is positive. therefore this is a false positive. the
implicit cast is not bad.

In this code example the dangerous casts has been taken care of properly.
Adding a cast instead is the wrong solution. However adding a cast is the
recommended approach by the checker - that is the only way to fix this warning.

This kind of false positive is indirectly a security problem. People routinely
hide these false positives using casts or changed variable types etc. and that
cause bugs and hides other real warnings.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to