bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#15634: coreutils-8.21 possible coding error ?


From: Eric Blake
Subject: bug#15634: coreutils-8.21 possible coding error ?
Date: Thu, 17 Oct 2013 05:19:44 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]