This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/15410] New: Coverity complains about if (true || true) in bits/stdio2.h
- From: "dank at kegel dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Fri, 26 Apr 2013 21:47:41 +0000
- Subject: [Bug libc/15410] New: Coverity complains about if (true || true) in bits/stdio2.h
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=15410
Bug #: 15410
Summary: Coverity complains about if (true || true) in
bits/stdio2.h
Product: glibc
Version: 2.18
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: unassigned@sourceware.org
ReportedBy: dank@kegel.com
CC: drepper.fsp@gmail.com
Classification: Unclassified
This affects user programs, and searching for the warning with google
dredges up at least one instance,
http://lists.eecs.utk.edu/pipermail/perfapi-devel/2012-November/005854.html
To reproduce the problem (assuming you have Coverity), create try.c containing
#include <stdio.h>
int main(int argc, char **argv)
{
char buf[128];
fread(buf, 1, 1, stdin);
}
then
PATH=/opt/coverity/cov-analysis-linux64-6.5.1/bin:$PATH
cov-configure --gcc
mkdir covlog
cov-build --dir covlog gcc -O2 try.c
cov-analyze --dir covlog
This outputs
...
Time taken by Coverity analysis : 00:00:01
Defect occurrences found : 2 Total
1 CHECKED_RETURN
1 CONSTANT_EXPRESSION_RESULT
and leaves behind the error log
covlog/c/output/CONSTANT_EXPRESSION_RESULT.errors.xml
which says
<file>/usr/include/x86_64-linux-gnu/bits/stdio2.h</file>
<tag>pointless_expression</tag>
<description>{CovLStrv2{{t{The expression {0} does not accomplish anything
becau
se it evaluates to either of its identical operands, {1}. Did you intend the
op
erands to be different?}{"1 /* !0 */ || 1 /* !0 */"}{"1 /* !0
*/&
quot;}}}}</description>
<line>279</line>
That's
279 if (!__builtin_constant_p (__size)
280 || !__builtin_constant_p (__n)
281 || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) /
2)))
282 return __fread_chk (__ptr, __bos0 (__ptr), __size, __n,
__stream);
Those lines have remained unchanged in git in libio/bits/stdio2.h for the
last five years, so this applies to both git and deployed versions.
The warning can be suppressed by patching the installed header, (e.g.)
/usr/include/x86_64-linux-gnu/bits/stdio2.h
with
--- a/libio/bits/stdio2.h
+++ b/libio/bits/stdio2.h
@@ -284,6 +284,8 @@ fread (void *__restrict __ptr, size_t __size, size_t __n,
{
if (__bos0 (__ptr) != (size_t) -1)
{
+ /* Suppress coverity warning about "if (true || true || foo)" */
+ /* coverity[pointless_expression] */
if (!__builtin_constant_p (__size)
|| !__builtin_constant_p (__n)
|| (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)))
It would be nice for Coverity users if glibc added this suppression comment.
Of course, then all the other static analysis tools would want special
treatment, too.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.