当我运行 Coverity 分析时,会在下面的函数中显示错误。
void initalizeStatement(sqlite3* db, const char* query)
{
// statement shall not be reuesed!
if (_valid) _valid = false;
else
{
sqlite3_stmt* stmt = NULL;
auto result = sqlite3_prepare(db, query, -1, &stmt, NULL);
if(SQLITE_OK != result)
{
DLT_LOG(dltContextSARMBUtils, DLT_LOG_ERROR,
DLT_STRING("[Statement::initalizeStatement()] sqlite3_prepare failed. status code : "),
DLT_INT(result),
DLT_STRING(", query : "),
DLT_STRING(query));
}
else //all good!
{
_valid = true;
_stmt = stmt;
_db = db;
}
}
}
我看到的错误如下:
<testcase name="[45] MISRA C++-2008 Rule 7-1-1 | misra_cpp_2008_rule_7_1_1_violation" time="0">
<failure message="The variable `query` has a non-const type, however its value is never changed. Consider adding a const qualifier to the variable type."> MBUtils::Statement::initalizeStatement(sqlite3*, char const*) </failure>
如果它已经有const
类型,为什么会显示这个错误?