Skip to content

Banned: Simplify alert messages, address compiler compat issues #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ where
f.getFile().getBaseName() = "wchar.h"
)
)
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
5 changes: 3 additions & 2 deletions c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ from Macro m, MacroInvocation mi
where
not isExcluded(mi, BannedPackage::standardHeaderFileTgmathhUsedQuery()) and
mi.getMacro() = m and
m.getFile().getBaseName() = "tgmath.h"
select mi, "Call to banned macro $@.", m, m.getName()
m.getFile().getBaseName() = "tgmath.h" and
not mi.getParentInvocation().getMacro().getFile().getBaseName() = "tgmath.h"
select mi, "Call to banned macro " + m.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ class FPExceptionHandlingMacro extends Macro {
}
}

from Locatable call, Locatable def, string name, string kind
from Locatable call, string name, string kind
where
not isExcluded(call, BannedPackage::exceptionHandlingFeaturesOfFenvhUsedQuery()) and
(
exists(FPExceptionHandlingFunction f |
def = f and
call = f.getACallToThisFunction() and
name = f.getName() and
kind = "function"
)
or
exists(FPExceptionHandlingMacro m |
def = m and
call = m.getAnInvocation() and
name = m.getName() and
kind = "macro"
kind = "macro" and
// Exclude macro invocations expanded from other macro invocations from macros in fenv.h.
not call.(MacroInvocation).getParentInvocation().getMacro().getFile().getBaseName() = "fenv.h"
)
)
select call, "Call to banned " + kind + " $@.", def, name
select call, "Call to banned " + kind + " " + name + "."
2 changes: 1 addition & 1 deletion c/misra/src/rules/RULE-21-21/SystemOfStdlibhUsed.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ where
not isExcluded(call, BannedPackage::systemOfStdlibhUsedQuery()) and
call.getTarget() = target and
target.hasGlobalOrStdName("system")
select call, "Call to banned function $@.", target, target.getName()
select call, "Call to banned function " + target.getName() + "."
6 changes: 2 additions & 4 deletions c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ class LongJmp extends Function {
}
}

from Locatable use, Locatable feature, string name
from Locatable use, string name
where
not isExcluded(use, BannedPackage::standardHeaderFileUsedSetjmphQuery()) and
(
exists(SetJmp setjmp |
feature = setjmp and
use = setjmp.getAnInvocation() and
name = "setjmp"
)
or
exists(LongJmp longjmp |
feature = longjmp and
use = longjmp.getACallToThisFunction() and
name = "longjmp"
)
)
select use, "Use of $@.", feature, name
select use, "Use of " + name + "."
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ where
not isExcluded(fc, BannedPackage::standardHeaderFileUsedSignalhQuery()) and
fc.getTarget() = f and
f.getFile().getBaseName() = "signal.h"
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ where
f.getName() = wcharInputOutput() and
f.getFile().getBaseName() = "wchar.h"
)
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ where
f = fc.getTarget() and
f.getName() = atoi() and
f.getFile().getBaseName() = "stdlib.h"
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ from FunctionCall fc, BannedFunction f
where
not isExcluded(fc, BannedPackage::terminationFunctionsOfStdlibhUsedQuery()) and
f = fc.getTarget()
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ from MacroInvocation mi, BannedMacro m
where
not isExcluded(mi, BannedPackage::terminationMacrosOfStdlibhUsedQuery()) and
m.getAnInvocation() = mi
select mi, "Use of banned macro $@.", m, m.getName()
select mi, "Use of banned macro " + m.getName() + "."
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ where
f = fc.getTarget() and
f.getName() = ["qsort", "bsearch"] and
f.getFile().getBaseName() = "stdlib.h"
select fc, "Call to banned function $@.", f, f.getName()
select fc, "Call to banned function " + f.getName() + "."
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| test.c:6:18:6:21 | call to time | Call to banned function $@. | time.h:53:8:53:11 | time | time |
| test.c:9:19:9:23 | call to ctime | Call to banned function $@. | time.h:60:7:60:11 | ctime | ctime |
| test.c:17:3:17:6 | call to time | Call to banned function $@. | time.h:53:8:53:11 | time | time |
| test.c:18:8:18:16 | call to localtime | Call to banned function $@. | time.h:58:12:58:20 | localtime | localtime |
| test.c:19:3:19:10 | call to wcsftime | Call to banned function $@. | wchar.h:139:8:139:15 | wcsftime | wcsftime |
| test.c:6:18:6:21 | call to time | Call to banned function time. |
| test.c:9:19:9:23 | call to ctime | Call to banned function ctime. |
| test.c:17:3:17:6 | call to time | Call to banned function time. |
| test.c:18:8:18:16 | call to localtime | Call to banned function localtime. |
| test.c:19:3:19:10 | call to wcsftime | Call to banned function wcsftime. |
4 changes: 2 additions & 2 deletions c/misra/test/rules/RULE-21-10/test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "time.h"
#include "wchar.h"
#include <time.h>
#include <wchar.h>
void f1() {
time_t current_time;
char *c_time_string;
Expand Down
166 changes: 0 additions & 166 deletions c/misra/test/rules/RULE-21-10/time.h

This file was deleted.

Loading