Skip to content

Commit 3bd65d4

Browse files
committed
posix.cfg: Fixed bufferAccessOutOfBounds falsen negative for strnlen() and added a TODO for wcsnlen()
1 parent dad1a68 commit 3bd65d4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

cfg/posix.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,6 +4723,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
47234723
<arg nr="1" direction="in">
47244724
<not-null/>
47254725
<not-uninit/>
4726+
<minsize type="argvalue" arg="2"/>
47264727
</arg>
47274728
<arg nr="2" direction="in">
47284729
<not-uninit/>

test/cfg/posix.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ int nullPointer_wcsnlen(const wchar_t *s, size_t n)
4848
return wcsnlen(s, n);
4949
}
5050

51+
size_t bufferAccessOutOfBounds_wcsnlen(const wchar_t *s, size_t maxlen)
52+
{
53+
wchar_t buf[2]={L'4',L'2'};
54+
size_t len = wcsnlen(buf,2);
55+
// TODO cppcheck-suppress bufferAccessOutOfBounds
56+
len+=wcsnlen(buf,3);
57+
return len;
58+
}
59+
5160
int nullPointer_gethostname(char *s, size_t n)
5261
{
5362
// cppcheck-suppress nullPointer
@@ -272,6 +281,23 @@ void bufferAccessOutOfBounds_bzero(void *s, size_t n)
272281
bzero(s,n);
273282
}
274283

284+
size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen)
285+
{
286+
char buf[2]={'4','2'};
287+
size_t len = strnlen(buf,2);
288+
// cppcheck-suppress bufferAccessOutOfBounds
289+
len+=strnlen(buf,3);
290+
return len;
291+
}
292+
293+
size_t nullPointer_strnlen(const char *s, size_t maxlen)
294+
{
295+
// No warning shall be shown:
296+
(void) strnlen(s, maxlen);
297+
// cppcheck-suppress nullPointer
298+
return strnlen(NULL, maxlen);
299+
}
300+
275301
char * nullPointer_stpcpy(char *src, char *dest)
276302
{
277303
// No warning shall be shown:

0 commit comments

Comments
 (0)