Bitfield size isn't error checked by Lint
Greetings,
I've been using Lint for the past 5 years and it's been a very useful tool for me. However, today I discovered an error in my C code that wasn't caught by Lint, and it may be useful if it could be flagged. The error is trying to divide a variable in a structure definition into bitfields where the combined size of the bitfields exceeds the size of the underlying variable.
For example, my bad code was like this:
typedef struct dummy_struct
{
unisgned char field1: 6,
field2: 6,
field3: 1,
field4: 1;
} DUMMY;
So, basically, I was trying to fit 14 bits into an 8-bit wide variable.
Regards,
Geoffrey
-
Hi Geoffrey,
Could you please clarify the specific circumstance you would like diagnosed by PC-lint Plus here? It is not clear what the underlying bug you encountered was from the example you provided.
-
Geoffrey Aldrich commented
Yes, that's just a typo in my example here. It doesn't reflect the actual code.
-
Anonymous commented
The data type has been wrongly typed. The data type should be "unsigned" instead of "unisgned" as mentioned in code.