File tree Expand file tree Collapse file tree 4 files changed +41
-16
lines changed Expand file tree Collapse file tree 4 files changed +41
-16
lines changed Original file line number Diff line number Diff line change 1414
1515import cpp
1616import filter
17-
18- class MemcpyFunction extends Function {
19- MemcpyFunction ( ) {
20- this .hasGlobalOrStdName ( "memcpy" )
21- or
22- this .hasGlobalName ( [ "fd_memcpy" , "__builtin_memcpy" ] )
23- }
24- }
17+ import fd_memcpy
2518
2619predicate ignoredLocation ( Location l ) {
2720 // we don't want to change vendored code if not really necessary
Original file line number Diff line number Diff line change 1313
1414import cpp
1515import filter
16-
17- class MemcpyFunction extends Function {
18- MemcpyFunction ( ) {
19- this .hasGlobalOrStdName ( "memcpy" )
20- or
21- this .hasGlobalName ( [ "fd_memcpy" , "__builtin_memcpy" ] )
22- }
23- }
16+ import fd_memcpy
2417
2518class NotVoidChar extends Type {
2619 NotVoidChar ( ) {
Original file line number Diff line number Diff line change 1+ /**
2+ * @name Suspicious/useless `memcpy(foo, foo, ...)` call.
3+ * @description `memcpy` is called with the same source and destination pointer.
4+ * This is likely a bug or at best useless code.
5+ * @kind problem
6+ * @id asymmetric-research/useless-memcpy
7+ * @problem.severity warning
8+ * @precision high
9+ * @tags correctness
10+ */
11+
12+ import cpp
13+ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
14+ import fd_memcpy
15+
16+ predicate isSamePointer ( Expr e1 , Expr e2 ) { globalValueNumber ( e1 ) = globalValueNumber ( e2 ) }
17+
18+ from MemcpyFunction memcpy , FunctionCall call
19+ where
20+ call .getTarget ( ) = memcpy and
21+ isSamePointer ( call .getArgument ( 0 ) , call .getArgument ( 1 ) )
22+ select call ,
23+ "Call to " + memcpy .getName ( ) +
24+ " has the same source and destination. This is likely a bug or useless code."
Original file line number Diff line number Diff line change 1+ import cpp
2+
3+ /**
4+ * A memcpy function:
5+ * - `memcpy` from `<string.h>`
6+ * - `fd_memcpy` from `fd_util_base.h`
7+ * - `__builtin_memcpy`
8+ */
9+ class MemcpyFunction extends Function {
10+ MemcpyFunction ( ) {
11+ this .hasGlobalOrStdName ( "memcpy" )
12+ or
13+ this .hasGlobalName ( [ "fd_memcpy" , "__builtin_memcpy" ] )
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments