#include<iostream>
main() {
char str[25]="";
// on line below cppcheck says: Buffer is accessed out of bounds
memset(&str,0,sizeof(str));
}
如注释中所述,由于str
被声明为char
array,然后使用str
(单独)作为memset
的第一个参数将产生第一个的地址元件。您添加了一个额外的“地址”运算符,该运算符可能(而且,似乎是[[does)使静态分析器混乱。
#include<iostream>
int main() {
char str[25] = "";
// on line below cppcheck says: Buffer is accessed out of bounds
memset(str, 0, sizeof(str));
// memset(&str[0], 0, sizeof(str)); // This is a more explicit alternative
//..
return 0;
}