Skip to content

Commit 5b61358

Browse files
committed
Improve regex to handle spaces
1 parent 7c3832f commit 5b61358

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

c/misra/src/rules/RULE-2-5/UnusedMacroDeclaration.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
bd.getHead() = m.getName()
3030
or
3131
// Covers the use of defined() to check if a macro is defined
32-
m.getName() = bd.getHead().regexpCapture(".*defined\\((.*)\\).*", 1)
32+
m.getName() = bd.getHead().regexpCapture(".*defined *\\(? *([^\\s()]+) *\\)?\\.*", 1)
3333
) and
3434
// We consider a macro "used" if the name is undef-ed at some point in the same file, or a file
3535
// that includes the file defining the macro. This will over approximate use in the case of a

c/misra/test/rules/RULE-2-5/test.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ void test() {
4242
#if defined(CHECKED_MACRO_BEFORE_3)
4343
#endif
4444

45+
#if defined(CHECKED_MACRO_BEFORE_4)
46+
#endif
47+
48+
#if defined(CHECKED_MACRO_BEFORE_5)
49+
#endif
50+
51+
#if defined(CHECKED_MACRO_BEFORE_6)
52+
#endif
53+
4554
#define CHECKED_MACRO_BEFORE_1 // COMPLIANT - used in branch
4655
#define CHECKED_MACRO_BEFORE_2 // COMPLIANT - used in branch
47-
#define CHECKED_MACRO_BEFORE_3 // COMPLIANT - used in branch
56+
#define CHECKED_MACRO_BEFORE_3 // COMPLIANT - used in branch
57+
#define CHECKED_MACRO_BEFORE_4 // COMPLIANT - used in branch
58+
#define CHECKED_MACRO_BEFORE_5 // COMPLIANT - used in branch
59+
#define CHECKED_MACRO_BEFORE_6 // COMPLIANT - used in branch

0 commit comments

Comments
 (0)