1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Correct the size argument to alloc functions
4 //# This makes an effort to find cases where the argument to sizeof is wrong
5 //# in memory allocation functions by checking the type of the allocated memory
6 //# when it is a double pointer and ensuring the sizeof argument takes a pointer
7 //# to the the memory being allocated. There are false positives in cases the
8 //# sizeof argument is not used in constructing the return value. The result
9 //# may need some reformatting.
11 // Confidence: Moderate
12 // Copyright: (C) 2014 Himangi Saraogi.
21 //----------------------------------------------------------
23 //----------------------------------------------------------
25 @depends on context disable sizeof_type_expr@
35 //----------------------------------------------------------
37 //----------------------------------------------------------
39 @depends on patch disable sizeof_type_expr@
50 //----------------------------------------------------------
51 // For org and report mode
52 //----------------------------------------------------------
54 @r depends on (org || report) disable sizeof_type_expr@
65 @script:python depends on org@
69 coccilib.org.print_todo(p[0], "WARNING sizeof argument should be pointer type, not structure type")
71 @script:python depends on report@
75 msg="WARNING: Use correct pointer type argument for sizeof"
76 coccilib.report.print_report(p[0], msg)