- What language is this for?
C - Which rule?
C:S3519 - Are you using
- SonarCloud
- SonarLint - Eclipse SonarLint 10.5
When the macro ARRAY_LENGTH is defined in the same file as where it is used, the overflow in the below code is detected. If the macro is moved to an h file and then included, then the buffer overflow does not generate a warning.
//#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))
uint16_t data[8];
uint16_t function(uint16_t in) {uint16_t out = 0; for (uint8_t i = 0; i <= ARRAY_LENGTH(data); i++) { out += data[i]; // Overflow at iteration 8 } return out;
}