Morag Agmon - 2024-12-29

Hello

Here is a code snippet similar to one we are doing, which triggers MISRA-C 2023 10.1 . Using cppcheckpremium 24.11.0

Rule 10.1 is about essential types operands, whereas pointers types are provided by rules 18.x .

What are we missing here?


typedef struct pt_foo_s {
  uint32_t aa;
  uint16_t bb;
  uint8_t  cc
} pt_foo_t;

typedef struct pt_bar_s {
  pt_foo_t *foos;
  uint16_t foos_num;
} pt_bar_t;

int main() {
  pt_bar_t bar;
  bar.foos = (pt_foo_t *)0xf00;
  bar.foos_num = 10u;

 // the below line sounds premium-misra-c-2023-10.1
  for (pt_foo_t *foo = bar->foos; foo < bar->foos + bar->foos_num; ++foo) {
    // whatever
  }

  return 0;
}
 

Last edit: Morag Agmon 2024-12-29