Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fragment of code from the Clang documentation page

Tags:

c++

c

clang

In the Clang documentation page there is a fragment of following code:

struct seven_words {
  int c[7];
};

void test() {
  struct seven_words a, *p;
  p = &a;
  p[0] = a;
  p[1] = a;
  p[2] = a; // warn
}

Why the checker warns only at the line with accesing to p[2] whereas there is a segmentation fault on line p[1] = a;. Is it a limit of the checker or there is something that I don't understand?

like image 712
Wojciech Marzec Avatar asked Dec 11 '25 15:12

Wojciech Marzec


1 Answers

The documentation is incorrect. (Or, if it correctly documents the behavior of the analyzer, the analyzer is deficient because it fails to detect a clear problem.)

like image 159
Eric Postpischil Avatar answered Dec 13 '25 05:12

Eric Postpischil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!