Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This compliant solution is explicit in which fields it modifies.:

Code Block
bgColor#ccccff
langc
struct bf {
  unsigned int m1 : 8;
  unsigned int m2 : 8;
  unsigned int m3 : 8;
  unsigned int m4 : 8;
}; /* 32 bits total */

void function() {
  struct bf data;
  data.m1 = 0;
  data.m2 = 0;
  data.m3 = 0;
  data.m4 = 0;
  data.m1++;
}

...

This compliant solution is explicit in which fields it modifies.:

Code Block
bgColor#ccccff
langc
struct bf {
  unsigned int m1 : 6;
  unsigned int m2 : 4;
};

void function() {
  struct bf data;
  data.m1 = 0;
  data.m2 = 0;
  data.m2 += 1;
}

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this recommendation. Specifically, it reports violations if

    • a pointer to one object is type cast to the pointer of a different object.
    • the pointed-to object of the (type cast) pointer is then modified arithmetically.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

94 S
95 S

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V
0310Partially implemented.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this recommendation on the CERT website.

...

Bibliography

[Plum 1985]Rule 6-5: In portable code, do not depend upon the allocation order of bit-fields within a word

...