GNU bug report logs - #11675
stty bad C semantics

Previous Next

Package: coreutils;

Reported by: Edward Schwartz <edmcman <at> cmu.edu>

Date: Mon, 11 Jun 2012 19:27:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

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: Edward Schwartz <edmcman <at> cmu.edu>
Cc: 11675 <at> debbugs.gnu.org
Subject: bug#11675: stty bad C semantics
Date: Mon, 11 Jun 2012 13:50:06 -0600
[Message part 1 (text/plain, inline)]
On 06/11/2012 01:16 PM, Edward Schwartz wrote:
> Hi,
> 
> I think there is a bug in main() of stty in coreutils 8.17.  The gist
> of the problem is that two structures are initialized:
> 
>    struct termios mode = { 0, };
> 
> and
> 
>   struct termios new_mode = { 0, };
> 
> They are then both modified, and then compared with memcmp.  The
> problem is that the structs contain padding bytes.  The C99 standard
> says "The value of padding bytes when storing values in structures or
> unions (6.2.6.1)." is unspecified, so the padding bytes may not be set
> to zero.

I disagree with your interpretation of C99, and claim instead that your
CIL compiler is buggy.

C99 6.7.8 para. 21:

"If there are fewer initializers in a brace-enclosed list than there are
elements or members of an aggregate, or fewer characters in a string
literal used to initialize an array of known size than there are
elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration."

And while there is no way to zero out padding bits by direct assignment,
I think we _are_ guaranteed that padding bits are zero when doing the
same initialization as static storage duration if we did not call out
all the named members.

> The problem is easily fixed by using memset, instead of implied
> initializations.  I am attaching a patch that does this.  While it
> won't affect most coreutils users, it might save some time for someone
> using a non-standard compiler or analysis platform.

If I understand correctly, gcc is also able to optimize out the memset,
so that your patch has no net impact and would allow us to work around
your buggy compiler; but I will leave it up to Jim whether it is worth
applying.

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

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

This bug report was last modified 12 years and 342 days ago.

Previous Next


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