Skip to content

Commit 18668a5

Browse files
committed
Library: Added buffer-size attribute for <alloc>
1 parent a325734 commit 18668a5

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

cfg/cppcheck-cfg.rng

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<optional>
3333
<attribute name="arg"><ref name="ARGNO"/></attribute>
3434
</optional>
35+
<optional>
36+
<attribute name="buffer-size"><ref name="DATA-BUFFER-SIZE"/></attribute>
37+
</optional>
3538
<ref name="DATA-NAME"/>
3639
</element>
3740
<element name="use"><ref name="DATA-EXTNAME"/></element>
@@ -458,6 +461,12 @@
458461
</data>
459462
</define>
460463

464+
<define name="DATA-BUFFER-SIZE">
465+
<data type="string">
466+
<param name="pattern">arg-value:[1-3]</param>
467+
</data>
468+
</define>
469+
461470
<define name="CONTAINER-ACTION">
462471
<choice>
463472
<value>resize</value>

cfg/std.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7320,7 +7320,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
73207320
<arg nr="2"/>
73217321
</function>
73227322
<memory>
7323-
<alloc init="false">malloc</alloc>
7323+
<alloc init="false" buffer-size="arg-value:1">malloc</alloc>
73247324
<alloc init="true">calloc</alloc>
73257325
<alloc init="false">aligned_alloc</alloc>
73267326
<alloc init="false">valloc</alloc>

lib/library.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
200200
temp.arg = atoi(arg);
201201
else
202202
temp.arg = -1;
203+
204+
const char *bufferSize = memorynode->Attribute("buffer-size");
205+
if (bufferSize && std::strncmp(bufferSize, "arg-value:", 10) == 0)
206+
temp.bufferSizeArgValue = bufferSize[10] - '0';
207+
else
208+
temp.bufferSizeArgValue = -1;
209+
203210
mAlloc[memorynode->GetText()] = temp;
204211
} else if (memorynodename == "dealloc") {
205212
AllocFunc temp;

lib/library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class CPPCHECKLIB Library {
7373
struct AllocFunc {
7474
int groupId;
7575
int arg;
76+
int bufferSizeArgValue;
7677
};
7778

7879
/** get allocation info for function */

0 commit comments

Comments
 (0)