Skip to content

Commit 9adcc36

Browse files
committed
Refine analysis messages
1 parent 4064b6b commit 9adcc36

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1717
import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1818

1919
class CtypeFunction extends Function {
20-
CtypeFunction() { this.getADeclaration().getAFile().(HeaderFile).getShortName() = "_ctype" }
20+
CtypeFunction() { this.getADeclaration().getAFile().(HeaderFile).getBaseName() = "ctype.h" }
2121
}
2222

2323
from FunctionCall ctypeCall
@@ -38,5 +38,5 @@ where
3838
)
3939
)
4040
select ctypeCall,
41-
"The <ctype.h> function $@ accepts an argument $@ that is not unsigned char nor an EOF.",
42-
ctypeCall, ctypeCall.getTarget(), ctypeCall.getAnArgument(), ctypeCall.getAnArgument().toString()
41+
"The <ctype.h> function " + ctypeCall + " accepts an argument " +
42+
ctypeCall.getAnArgument().toString() + " that is not an unsigned char nor an EOF."

c/misra/src/rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ class MemCmpMoveCpy extends Function {
2222
}
2323
}
2424

25-
predicate memfunArgTypes(FunctionCall fc, Type dstType, Type srcType) {
26-
(
27-
fc.getArgument(0).getUnspecifiedType() instanceof PointerType and
28-
fc.getArgument(1).getUnspecifiedType() instanceof PointerType
29-
or
30-
fc.getArgument(0).getUnspecifiedType() instanceof ArrayType and
31-
fc.getArgument(1).getUnspecifiedType() instanceof ArrayType
32-
) and
33-
dstType = fc.getArgument(0).getUnspecifiedType() and
34-
srcType = fc.getArgument(1).getUnspecifiedType()
35-
}
36-
3725
from FunctionCall fc
3826
where
3927
not isExcluded(fc,
@@ -50,4 +38,7 @@ where
5038
) and
5139
dstType = srcType
5240
)
53-
select fc, fc.getArgument(0).getUnspecifiedType(), fc.getArgument(1).getUnspecifiedType()
41+
select fc,
42+
"The dest type " + fc.getArgument(0).getUnspecifiedType() + " and src type " +
43+
fc.getArgument(1).getUnspecifiedType() + " of function " + fc.getTarget() +
44+
" are not compatible."
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
| test.c:15:12:15:22 | call to islower | test.c:15:20:15:21 | c3 |
1+
| test.c:15:12:15:22 | call to islower | The <ctype.h> function call to islower accepts an argument c3 that is not an unsigned char nor an EOF. |
2+
| test.c:20:12:20:22 | call to isdigit | The <ctype.h> function call to isdigit accepts an argument c4 that is not an unsigned char nor an EOF. |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.c:10:3:10:8 | call to memcpy | file://:0:0:0:0 | int * | file://:0:0:0:0 | int * |
2-
| test.c:14:3:14:9 | call to memmove | file://:0:0:0:0 | char[7] | file://:0:0:0:0 | char[7] |
3-
| test.c:22:3:22:8 | call to memcmp | file://:0:0:0:0 | char[7] | file://:0:0:0:0 | char[7] |
1+
| test.c:10:3:10:8 | call to memcpy | The dest type int * and src type int * of function memcpy are not compatible. |
2+
| test.c:14:3:14:9 | call to memmove | The dest type char[7] and src type char[7] of function memmove are not compatible. |
3+
| test.c:22:3:22:8 | call to memcmp | The dest type char[7] and src type char[7] of function memcmp are not compatible. |

0 commit comments

Comments
 (0)