#6077: Don't warn about memcpy/memmove on class containing floats.
This commit is contained in:
parent
c678937538
commit
f01d7543f6
|
@ -1037,8 +1037,8 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
||||||
checkMemsetType(start, tok, typeScope, allocation, parsedTypes);
|
checkMemsetType(start, tok, typeScope, allocation, parsedTypes);
|
||||||
|
|
||||||
// check for float
|
// check for float
|
||||||
else if (var->isFloatingType() && _settings->isEnabled("portability"))
|
else if (tok->str() == "memset" && var->isFloatingType() && _settings->isEnabled("portability"))
|
||||||
memsetErrorFloat(tok, tok->str(), type->classDef->str());
|
memsetErrorFloat(tok, type->classDef->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1079,10 +1079,10 @@ void CheckClass::memsetErrorReference(const Token *tok, const std::string &memfu
|
||||||
reportError(tok, Severity::error, "memsetClassReference", "Using '" + memfunc + "' on " + type + " that contains a reference.");
|
reportError(tok, Severity::error, "memsetClassReference", "Using '" + memfunc + "' on " + type + " that contains a reference.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::memsetErrorFloat(const Token *tok, const std::string &memfunc, const std::string &type)
|
void CheckClass::memsetErrorFloat(const Token *tok, const std::string &type)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::portability, "memsetClassFloat", "Using '" + memfunc + "' on " + type + " which contains a floating point number.\n"
|
reportError(tok, Severity::portability, "memsetClassFloat", "Using memset() on " + type + " which contains a floating point number.\n"
|
||||||
"Using '" + memfunc + "' on " + type + " which contains a floating point number. This is not portable because memset() sets each byte of a block of memory to a specific value and"
|
"Using memset() on " + type + " which contains a floating point number. This is not portable because memset() sets each byte of a block of memory to a specific value and"
|
||||||
" the actual representation of a floating-point value is implementation defined.");
|
" the actual representation of a floating-point value is implementation defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ private:
|
||||||
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
|
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||||
void memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type);
|
void memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type);
|
||||||
void memsetErrorReference(const Token *tok, const std::string &memfunc, const std::string &type);
|
void memsetErrorReference(const Token *tok, const std::string &memfunc, const std::string &type);
|
||||||
void memsetErrorFloat(const Token *tok, const std::string &memfunc, const std::string &type);
|
void memsetErrorFloat(const Token *tok, const std::string &type);
|
||||||
void mallocOnClassError(const Token* tok, const std::string &memfunc, const Token* classTok, const std::string &classname);
|
void mallocOnClassError(const Token* tok, const std::string &memfunc, const Token* classTok, const std::string &classname);
|
||||||
void mallocOnClassWarning(const Token* tok, const std::string &memfunc, const Token* classTok);
|
void mallocOnClassWarning(const Token* tok, const std::string &memfunc, const Token* classTok);
|
||||||
void operatorEqReturnError(const Token *tok, const std::string &className);
|
void operatorEqReturnError(const Token *tok, const std::string &className);
|
||||||
|
@ -171,7 +171,7 @@ private:
|
||||||
c.unusedPrivateFunctionError(0, "classname", "funcname");
|
c.unusedPrivateFunctionError(0, "classname", "funcname");
|
||||||
c.memsetError(0, "memfunc", "classname", "class");
|
c.memsetError(0, "memfunc", "classname", "class");
|
||||||
c.memsetErrorReference(0, "memfunc", "class");
|
c.memsetErrorReference(0, "memfunc", "class");
|
||||||
c.memsetErrorFloat(0, "memfunc", "class");
|
c.memsetErrorFloat(0, "class");
|
||||||
c.mallocOnClassWarning(0, "malloc", 0);
|
c.mallocOnClassWarning(0, "malloc", 0);
|
||||||
c.mallocOnClassError(0, "malloc", 0, "std::string");
|
c.mallocOnClassError(0, "malloc", 0, "std::string");
|
||||||
c.operatorEqReturnError(0, "class");
|
c.operatorEqReturnError(0, "class");
|
||||||
|
|
|
@ -2481,7 +2481,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}", false, true);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (portability) Using 'memset' on struct which contains a floating point number.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
checkNoMemset("struct A {\n"
|
||||||
" float f[4];\n"
|
" float f[4];\n"
|
||||||
|
@ -2490,7 +2490,16 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}", false, true);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (portability) Using 'memset' on struct which contains a floating point number.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
||||||
|
|
||||||
|
checkNoMemset("struct A {\n"
|
||||||
|
" float f[4];\n"
|
||||||
|
"};\n"
|
||||||
|
"void f(const A& b) {\n"
|
||||||
|
" A a;\n"
|
||||||
|
" memcpy(&a, &b, sizeof(A));\n"
|
||||||
|
"}", false, true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
checkNoMemset("struct A {\n"
|
||||||
" float* f;\n"
|
" float* f;\n"
|
||||||
|
|
Loading…
Reference in New Issue