Skip to content

Commit b1b7593

Browse files
author
Daniel Marjamäki
committed
Updates here and there to make it more accurate
1 parent 85a5010 commit b1b7593

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

CheckOther.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,12 @@ void CheckUnsignedDivision()
494494
TOKEN *tokdiv = findtoken(declvar, pattern_div1);
495495
while ( tokdiv )
496496
{
497-
std::ostringstream ostr;
498-
ostr << FileLine(tokdiv) << ": If the result is negative it will be wrong because an operand is unsigned.";
499-
ReportErr(ostr.str());
497+
if ( strcmp(getstr(tokdiv,2), "->") )
498+
{
499+
std::ostringstream ostr;
500+
ostr << FileLine(tokdiv) << ": If the result is negative it will be wrong because an operand is unsigned.";
501+
ReportErr(ostr.str());
502+
}
500503
tokdiv = findtoken(tokdiv->next, pattern_div1);
501504
}
502505

@@ -505,7 +508,9 @@ void CheckUnsignedDivision()
505508
tokdiv = findtoken(declvar, pattern_div2);
506509
while ( tokdiv )
507510
{
508-
if (!IsNumber(getstr(tokdiv,3)) && tokdiv->str[0]!=')') // The ')' may indicate a cast
511+
if (!IsNumber(getstr(tokdiv,3)) &&
512+
tokdiv->str[0] != ')' && // The ')' may indicate a cast
513+
strcmp(tokdiv->str,"->"))
509514
{
510515
std::ostringstream ostr;
511516
ostr << FileLine(tokdiv) << ": If the result is negative it will be wrong because an operand is unsigned.";

Statements.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ void CreateStatementList()
223223
ismalloc |= match(rs, "( type * * ) malloc (");
224224
ismalloc |= match(rs, "( type type * ) malloc (");
225225
ismalloc |= match(rs, "( type type * * ) malloc (");
226+
ismalloc |= match(rs, "( type * ) kmalloc (");
227+
ismalloc |= match(rs, "( type * * ) kmalloc (");
228+
ismalloc |= match(rs, "( type type * ) kmalloc (");
229+
ismalloc |= match(rs, "( type type * * ) kmalloc (");
226230
}
227231

228232
if ( ismalloc )
@@ -253,6 +257,9 @@ void CreateStatementList()
253257
if (match(tok2, "free ( var ) ;"))
254258
AppendStatement(STATEMENT::FREE, tok2, getstr(tok2, 2));
255259

260+
if (match(tok2, "kfree ( var ) ;"))
261+
AppendStatement(STATEMENT::FREE, tok2, getstr(tok2, 2));
262+
256263
if (match(tok2, "delete var ;"))
257264
AppendStatement(STATEMENT::DELETE, tok2, getstr(tok2,1));
258265

main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,6 @@ static void CppCheck(const char FileName[])
219219
// Dangerous usage of strtok
220220
// Disabled because it generates false positives
221221
//WarningStrTok();
222-
223-
// Variable scope
224-
CheckVariableScope();
225222
}
226223

227224

@@ -262,6 +259,9 @@ static void CppCheck(const char FileName[])
262259

263260
// if (condition);
264261
WarningIf();
262+
263+
// Variable scope
264+
CheckVariableScope();
265265
}
266266

267267

0 commit comments

Comments
 (0)