Klocwork produit une alarme qui semble être fausse. Le bug qu'il mentionne décrit environ 80% du nombre total de bogues dans notre code. S'il vous plaît conseiller,Non annulé chaîne terminée fausse alarme?
est un ensemble Par la présente snip (paraphrase): -
//a snip set
// no bug here //
{
char* destStr;
destStr = (char*)malloc(150);
if (destStr != NULL) {
destStr[0]= '\0'; //__here is the difference__
char * myStr = malloc(200) ;
if (myStr != NULL) {
strcpy(myStr , destStr) ;
}
free(myStr);
}
free (destStr);
destStr = NULL;
}
//__whereas a bug here__ !
{
char* destStr;
destStr = (char*) malloc(150);
if (destStr != NULL) {
destStr[0]= '\0'; // __here is the difference__
}
else {
printf("hello world \n");
}
if (destStr != NULL) {
char * myStr = malloc(200);
if (myStr != NULL) {
strcpy(myStr , destStr); // __NNTS (not NULL terminated string) – Buffer overflow of 'myStr' due to non null terminated string 'destStr'.__
}
free (myStr);
}
free (destStr);
destStr = NULL;
}
//end of snip set
double possible [chaîne de caractères terminée Non null -. Une erreur Klocwork sans raison compréhensible] (http : //stackoverflow.com/questions/3181018/not-null-terminated-string-a-klocwork-error-with-no-understandable-reason) – kiamlaluno