GNU bug report logs - #15634
coreutils-8.21 possible coding error ?

Previous Next

Package: coreutils;

Reported by: David Binderman <dcb314 <at> hotmail.com>

Date: Thu, 17 Oct 2013 07:55:02 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: David Binderman <dcb314 <at> hotmail.com>, 15634 <at> debbugs.gnu.org
Subject: bug#15634: coreutils-8.21 possible coding error ?
Date: Thu, 17 Oct 2013 05:19:44 -0600
[Message part 1 (text/plain, inline)]
On 10/17/2013 01:33 AM, David Binderman wrote:
> Hello there,
> 
> I just ran the static analysis tool cppcheck over the source code
> of coreutils-8.21

Thanks for reporting that.

> 
> It said many things, including
> 
> [src/dircolors.c:445]: (warning) Comparison of a boolean value using relational operator (<,>, <= or>=).
> 
> Source code is
> 
>   if (!print_database < argc)
> 
> Some round brackets might help clarify the code
> 
>   if ((!print_database) < argc)

This is the intended form; gcc doesn't warn about the precedence, but
silencing cppcheck may be worth it.

> 
> or was perhaps
> 
>   if (!(print_database < argc))
> 
> intended ? Here are some other things cppcheck found.
> 
> [lib/mountlist.c:945]: (error) Resource leak: dirp

This one has already been fixed in gnulib (commit 98171ec); it will be
fixed in coreutils the next time coreutils updates to latest gnulib.

> [lib/sig2str.c:329]: (warning) Logical conjunction always evaluates to false: signum <= -1 && signum>= 0.

Line 329 is:
    if (! (rtmin <= signum && signum <= rtmax))
with rtmin set to SIGRTMIN.  I'm not sure I follow how the error message
is claiming we are comparing signum <= -1.  Bug in cppcheck?

> [lib/closein.c:91]: (error) fflush() called on input stream 'stdin' results in undefined behaviour.

Bug in cppcheck.  Calling fflush(stdin) IS defined behavior, if stdin is
seekable (which the code prior to that line guaranteed).  POSIX 2013
explicitly says so:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html

[CX] [Option Start] For a stream open for reading, if the file is not
already at EOF, and the file is one capable of seeking, the file offset
of the underlying open file description shall be set to the file
position of the stream, and any characters pushed back onto the stream
by ungetc() or ungetwc() that have not subsequently been read from the
stream shall be discarded (without further changing the file offset).
[Option End]

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 6 years and 284 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.