public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
* Packed struct size issue
@ 2019-07-17 13:42 John Levon
  2019-07-18 10:16 ` Dan Carpenter
  2019-07-18 10:50 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: John Levon @ 2019-07-17 13:42 UTC (permalink / raw)
  To: smatch; +Cc: andy


Andy Fiddaman discovered:

$ cat ./test.c
#include <stdio.h>
#include <stdint.h>

struct t1 {
        uint8_t                 critical_warning;
        uint16_t                temperature;
        uint8_t                 available_spare;
} __packed;

_Static_assert(sizeof(struct t1) == 4, "bad size for t1");

struct t2 {
        uint8_t                 critical_warning;
        uint16_t                temperature;
        uint8_t                 available_spare;
};

_Static_assert(sizeof(struct t2) == 6, "bad size for t2");

$ ./smatch ./test.c
./test.c:10:34: error: static assertion failed: "bad size for t1"


Looks like we lost this commit:
https://github.com/illumos/smatch/commit/0c60237e4096b7576f0aec21a7545026c7041611#diff-0cd054d23ed9e02274eaa540fc7e6536

??

This works:

https://github.com/citrus-it/illumos-omnios/commit/88e29e1705a616695ec6f905c3cab1f600e12659?diff=unified

regards
john

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Packed struct size issue
  2019-07-17 13:42 Packed struct size issue John Levon
@ 2019-07-18 10:16 ` Dan Carpenter
  2019-07-18 10:50 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-07-18 10:16 UTC (permalink / raw)
  To: John Levon; +Cc: smatch, andy, sparse

On Wed, Jul 17, 2019 at 02:42:34PM +0100, John Levon wrote:
> 
> Andy Fiddaman discovered:
> 
> $ cat ./test.c
> #include <stdio.h>
> #include <stdint.h>
> 
> struct t1 {
>         uint8_t                 critical_warning;
>         uint16_t                temperature;
>         uint8_t                 available_spare;
> } __packed;
> 
> _Static_assert(sizeof(struct t1) == 4, "bad size for t1");
> 

I've added Sparse mailing list to the CC.

It looks like the packed attribute is broken on upstream Sparse (from
April) as well and I would prefer if they fixed it and I pulled in their
fix.  It's probably better to use __attribute__((packed)) instead of the
__packed macro in the test code.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Packed struct size issue
  2019-07-17 13:42 Packed struct size issue John Levon
  2019-07-18 10:16 ` Dan Carpenter
@ 2019-07-18 10:50 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-07-18 10:50 UTC (permalink / raw)
  To: John Levon; +Cc: smatch, andy, linux-sparse

[ resending to the correct Sparse email address ].

On Wed, Jul 17, 2019 at 02:42:34PM +0100, John Levon wrote:
> 
> Andy Fiddaman discovered:
> 
> $ cat ./test.c
> #include <stdio.h>
> #include <stdint.h>
> 
> struct t1 {
>         uint8_t                 critical_warning;
>         uint16_t                temperature;
>         uint8_t                 available_spare;
> } __packed;
> 
> _Static_assert(sizeof(struct t1) == 4, "bad size for t1");
> 

I've added Sparse mailing list to the CC.

It looks like the packed attribute is broken on upstream Sparse (from
April) as well and I would prefer if they fixed it and I pulled in their
fix.  It's probably better to use __attribute__((packed)) instead of the
__packed macro in the test code.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-18 10:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-17 13:42 Packed struct size issue John Levon
2019-07-18 10:16 ` Dan Carpenter
2019-07-18 10:50 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox