Fixed #823 (Buffer overrun with memcpy)

This commit is contained in:
Daniel Marjamäki 2009-10-15 19:36:48 +02:00
parent 2a034c10bf
commit 01af70cc88
2 changed files with 18 additions and 18 deletions

View File

@ -88,7 +88,7 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok)
severity = Severity::error;
}
reportError(tok, severity, "bufferOverrun", "Buffer overrun");
reportError(tok, severity, "bufferAccessOutOfBounds", "Buffer access out-of-bounds");
}
void CheckBufferOverrun::dangerousStdCin(const Token *tok)

View File

@ -270,7 +270,7 @@ private:
" for (i = 0; i < 100; i++)\n"
" sum += val[i];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str());
}
{
@ -281,7 +281,7 @@ private:
" for (i = 1; i < 100; i++)\n"
" sum += val[i];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str());
}
@ -293,7 +293,7 @@ private:
" for (i = a; i < 100; i++)\n"
" sum += val[i];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str());
}
}
@ -630,7 +630,7 @@ private:
" char str[3];\n"
" strcpy(str, \"abc\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
@ -645,7 +645,7 @@ private:
"{\n"
" strcpy( abc->str, \"abcdef\" );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:8]: (error) Buffer access out-of-bounds\n", errout.str());
}
@ -659,7 +659,7 @@ private:
" for (i = 0; i <= 10; ++i)\n"
" a[i] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:7]: (error) Buffer access out-of-bounds\n", errout.str());
}
@ -671,7 +671,7 @@ private:
" for (int i = 0; i < 8; ++i)\n"
" p[i] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer access out-of-bounds\n", errout.str());
// No false positive
check("void foo(int x, int y)\n"
@ -692,7 +692,7 @@ private:
" char s[3];\n"
" f1(s,3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (possible error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (possible error) Buffer access out-of-bounds\n", errout.str());
TODO_ASSERT_EQUALS("", errout.str());
check("void f1(char *s,int size)\n"
@ -726,14 +726,14 @@ private:
" strcat(n, \"abc\");\n"
" strcat(n, \"def\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
" char n[5];\n"
" strcat(strcat(n, \"abc\"), \"def\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
void buffer_overrun_7()
@ -847,7 +847,7 @@ private:
" char str[3];\n"
" sprintf(str, \"%s\", \"abc\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
@ -855,7 +855,7 @@ private:
" sprintf(c, \"%s\", \"/usr/LongLongLongLongUserName/bin/LongLongApplicationName\");\n"
" delete [] c;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
void sprintf2()
@ -865,7 +865,7 @@ private:
" char str[5];\n"
" sprintf(str, \"%d: %s\", getnumber(), \"abcde\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
void sprintf3()
@ -875,7 +875,7 @@ private:
" char str[3];\n"
" sprintf(str, \"test\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
@ -914,7 +914,7 @@ private:
" char buf[3];\n"
" sprintf(buf, \"%s\", condition ? \"11\" : \"222\");\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
void snprintf1()
@ -1159,7 +1159,7 @@ private:
" strcpy(a,\"hello\");\n"
" strncpy(c,a,sizeof(c)+1);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
@ -1173,7 +1173,7 @@ private:
" char c[6];\n"
" strncpy(c,\"hello!\",sizeof(c)+1);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}
};