Packed struct size issue
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:
regards
john
Quoted 7 lines · John Levon
Andy Fiddaman discovered:
$ cat ./test.c #include <stdio.h> #include <stdint.h>
Quoted 8 lines
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
[ resending to the correct Sparse email address ].
Quoted 7 lines · John Levon
Andy Fiddaman discovered:
$ cat ./test.c #include <stdio.h> #include <stdint.h>
Quoted 8 lines
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