Skip to content

Commit 5cbed04

Browse files
authored
opencv2.cfg: Add types, macros, functions and memory (de)allocation (#2620)
* opencv2.cfg: Add types, macros, functions and memory (de)allocation * cfg/cppcheck-cfg.rng: Allow alloc/realloc functions in classes
1 parent eed2e82 commit 5cbed04

3 files changed

Lines changed: 75 additions & 4 deletions

File tree

cfg/cppcheck-cfg.rng

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<optional>
3636
<attribute name="buffer-size"><ref name="DATA-BUFFER-SIZE"/></attribute>
3737
</optional>
38-
<ref name="DATA-NAME"/>
38+
<ref name="DATA-EXTNAME-SINGLE"/>
3939
</element>
4040
<element name="realloc">
4141
<optional>
@@ -50,7 +50,7 @@
5050
<optional>
5151
<attribute name="realloc-arg"><ref name="ARGNO"/></attribute>
5252
</optional>
53-
<ref name="DATA-NAME"/>
53+
<ref name="DATA-EXTNAME-SINGLE"/>
5454
</element>
5555
<element name="use"><ref name="DATA-EXTNAME"/></element>
5656
</choice>
@@ -75,7 +75,7 @@
7575
<optional>
7676
<attribute name="arg"><ref name="ARGNO"/></attribute>
7777
</optional>
78-
<ref name="DATA-NAME"/>
78+
<ref name="DATA-EXTNAME-SINGLE"/>
7979
</element>
8080
<element name="realloc">
8181
<optional>
@@ -87,7 +87,7 @@
8787
<optional>
8888
<attribute name="realloc-arg"><ref name="ARGNO"/></attribute>
8989
</optional>
90-
<ref name="DATA-NAME"/>
90+
<ref name="DATA-EXTNAME-SINGLE"/>
9191
</element>
9292
<element name="use"><ref name="DATA-EXTNAME"/></element>
9393
</choice>
@@ -570,6 +570,12 @@
570570
</data>
571571
</define>
572572

573+
<define name="DATA-EXTNAME-SINGLE">
574+
<data type="string">
575+
<param name="pattern">[a-zA-Z_][a-zA-Z_0-9:]*</param>
576+
</data>
577+
</define>
578+
573579
<define name="DATA-EXTNAME">
574580
<data type="string">
575581
<param name="pattern">[a-zA-Z_][a-zA-Z_0-9:,]*</param>

cfg/opencv2.cfg

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
<!-- The OpenCV library is typically included by '#include <opencv2/*>' or -->
66
<!-- '#include "opencv2/*"'. -->
77
<!-- ########## OpenCV Types ########## -->
8+
<podtype name="cv::int8_t" sign="s" size="1"/>
9+
<podtype name="cv::int16_t" sign="s" size="2"/>
10+
<podtype name="cv::int32_t" sign="s" size="4"/>
11+
<podtype name="cv::int64_t" sign="s" size="8"/>
12+
<podtype name="cv::uint8_t" sign="u" size="1"/>
13+
<podtype name="cv::uint16_t" sign="u" size="2"/>
14+
<podtype name="cv::uint32_t" sign="u" size="4"/>
15+
<podtype name="cv::uint64_t" sign="u" size="8"/>
16+
<smart-pointer class-name="cv::Ptr"/>
817
<!-- ########## OpenCV Macros / Defines ########## -->
18+
<define name="CV_ALWAYS_INLINE" value="inline"/>
19+
<define name="CV_EXTERN_C" value="extern &quot;C&quot;"/>
20+
<define name="CV_OVERRIDE" value="override"/>
921
<define name="CV_PI" value="3.1415926535897932384626433832795"/>
1022
<define name="CV_2PI" value="6.283185307179586476925286766559"/>
1123
<define name="CV_LOG2" value="0.69314718055994530941723212145818"/>
@@ -22,11 +34,54 @@
2234
<define name="CV_IS_SUBMAT(flags)" value="((flags) &amp; CV_MAT_SUBMAT_FLAG)"/>
2335
<define name="MIN(a,b)" value="((a) &gt; (b) ? (b) : (a))"/>
2436
<define name="MAX(a,b)" value="((a) &lt; (b) ? (b) : (a))"/>
37+
<define name="CV_Error(code,msg)" value="cv::error( code, msg, CV_Func, __FILE__, __LINE__ )"/>
38+
<define name="CV_Assert(expr)" value="do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)"/>
2539
<!-- ########## OpenCV containers ########## -->
2640
<!-- OpenCV containers that are similar to std containers -->
2741
<container id="cvString" startPattern="cv :: String" inherits="stdString"/>
2842
<!-- ########## OpenCV Allocation / Deallocation ########## -->
43+
<memory>
44+
<alloc init="false" buffer-size="malloc">cv::fastMalloc</alloc>
45+
<dealloc>cv::fastFree</dealloc>
46+
</memory>
2947
<!-- ########## OpenCV Functions ########## -->
48+
<!-- void cv::errorNoReturn (int _code, const String & _err, const char * _func, const char * _file, int _line) -->
49+
<function name="cv::errorNoReturn">
50+
<noreturn>true</noreturn>
51+
<arg nr="1" direction="in">
52+
<not-uninit/>
53+
</arg>
54+
<arg nr="2" direction="in">
55+
<not-uninit/>
56+
</arg>
57+
<arg nr="3" direction="in">
58+
<not-uninit/>
59+
</arg>
60+
<arg nr="4" direction="in">
61+
<not-uninit/>
62+
</arg>
63+
<arg nr="5" direction="in">
64+
<not-uninit/>
65+
</arg>
66+
</function>
67+
<!-- void cv::fastFree (void *ptr) -->
68+
<function name="cv::fastFree">
69+
<noreturn>false</noreturn>
70+
<returnValue type="void"/>
71+
<arg nr="1">
72+
<not-uninit indirect="1"/>
73+
</arg>
74+
</function>
75+
<!-- void * cv::fastMalloc (size_t bufSize) -->
76+
<function name="cv::fastMalloc">
77+
<noreturn>false</noreturn>
78+
<returnValue type="void *"/>
79+
<use-retval/>
80+
<arg nr="1" direction="in">
81+
<not-uninit/>
82+
<valid>0:</valid>
83+
</arg>
84+
</function>
3085
<!-- Mat cv::imread ( const String & filename, int flags = IMREAD_COLOR ) -->
3186
<function name="cv::imread">
3287
<noreturn>false</noreturn>

test/cfg/opencv2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ void validCode(char* argStr)
2626
cv::String cvStr("Hello");
2727
cvStr += " World";
2828
std::cout << cvStr;
29+
30+
char * pBuf = (char *)cv::fastMalloc(20);
31+
cv::fastFree(pBuf);
2932
}
3033

3134
void ignoredReturnValue()
3235
{
3336
// cppcheck-suppress ignoredReturnValue
3437
cv::imread("42.png");
3538
}
39+
40+
void memleak()
41+
{
42+
char * pBuf = (char *)cv::fastMalloc(1000);
43+
std::cout << pBuf;
44+
// cppcheck-suppress memleak
45+
}

0 commit comments

Comments
 (0)