CWARN.PACKED.TYPEDEF

Attribute 'packed' is ignored in typedef

The CWARN.PACKED.TYPEDEF checker finds instances in which the gcc 'packed' attribute is applied to a typedef declaration. The 'packed' attribute is allowed when a typedef includes a struct definition.

Vulnerable code example

Copy
  typedef struct test{
    int a;
    char b;
    int c;
  } __attribute__((__packed__)) testing;
    /* ... */ 
   typedef struct s __attribute__((packed)) s_packed;   
   /* ... */ 

Klocwork flags line 7, in which the 'packed' attribute is used with a typedef declaration. The 'packed' attribute in line 5 isn't flagged, since it's part of the struct definition.