[llvm-bugs] [Bug 34817] New: False positive on reading undefined value from streams
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Oct 3 09:16:48 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34817
Bug ID: 34817
Summary: False positive on reading undefined value from streams
Product: clang
Version: trunk
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: enhancement
Priority: P
Component: Static Analyzer
Assignee: kremenek at apple.com
Reporter: howard.hinnant at gmail.com
CC: llvm-bugs at lists.llvm.org
This code gets an analyzer warning:
#include <cassert>
#include <sstream>
int
main()
{
std::istringstream in{""};
char c;
in >> c;
assert(!in.fail());
return int{c};
}
scan-build: Using '/Users/howardhinnant/Development/llvm_build/bin/clang-6.0'
for static analysis
test.cpp:492:5: warning: Undefined or garbage value returned to caller
return int{c};
^~~~~~~~~~~~~
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view
/var/folders/7d/bq37f_s53dbgw_z48smv9q9m0000gn/T/scan-build-2017-10-03-121247-59896-1'
to examine bug reports.
It would be nice if the analyzer could detect that c can't be garbage because
in.fail() is checked and if true never reaches the use of c.
Even better would be this:
#include <cassert>
#include <sstream>
int
main()
{
std::istringstream in{""};
in.exceptions(std::ios::failbit | std::ios::badbit);
assert(((std::ios::failbit | std::ios::badbit) & in.exceptions()) ==
(std::ios::failbit | std::ios::badbit));
char c;
in >> c;
return int{c};
}
c can not be used with garbage, proven by the settings in in.exceptions(). So
no warning on the above either.
--
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/20171003/509f6df8/attachment.html>
More information about the llvm-bugs
mailing list