gnu.cfg: Added support for asprintf() and vasprintf(). There is a FN with memory leak detection regarding pointer args, which is already mentioned in #8980. A comment has been added.

This commit is contained in:
Martin Ettl 2019-02-27 15:17:34 +01:00
parent 084c7c284e
commit 17c1733b0e
2 changed files with 50 additions and 2 deletions

View File

@ -4,6 +4,43 @@
<dealloc>free</dealloc> <dealloc>free</dealloc>
<alloc init="true">get_current_dir_name</alloc> <alloc init="true">get_current_dir_name</alloc>
</memory> </memory>
<memory>
<alloc init="true" arg="1">asprintf</alloc>
<dealloc>free</dealloc>
</memory>
<!-- http://man7.org/linux/man-pages/man3/asprintf.3.html -->
<!-- int asprintf(char **strp, const char *fmt, ...); -->
<function name="asprintf">
<returnValue type="int"/>
<use-retval/>
<noreturn>false</noreturn>
<arg nr="1">
<not-null/>
</arg>
<formatstr/>
<arg nr="2">
<formatstr/>
<not-uninit/>
</arg>
</function>
<!-- http://man7.org/linux/man-pages/man3/asprintf.3.html -->
<!-- int vasprintf(char **strp, const char *fmt, va_list ap); -->
<function name="vasprintf">
<returnValue type="int"/>
<use-retval/>
<noreturn>false</noreturn>
<arg nr="1">
<not-null/>
</arg>
<formatstr/>
<arg nr="2">
<formatstr/>
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!-- http://man7.org/linux/man-pages/man2/accept.2.html --> <!-- http://man7.org/linux/man-pages/man2/accept.2.html -->
<!-- int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); --> <!-- int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); -->
<function name="accept4"> <function name="accept4">
@ -26,8 +63,7 @@
</function> </function>
<!-- int getopt_long(int argc, char * const argv[], <!-- int getopt_long(int argc, char * const argv[],
const char *optstring, const char *optstring,
const struct option *longopts, int *longindex); const struct option *longopts, int *longindex); -->
-->
<function name="getopt_long,getopt_long_only"> <function name="getopt_long,getopt_long_only">
<leak-ignore/> <leak-ignore/>
<noreturn>false</noreturn> <noreturn>false</noreturn>

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#ifndef __CYGWIN__ #ifndef __CYGWIN__
#include <sys/epoll.h> #include <sys/epoll.h>
#endif #endif
@ -21,6 +22,17 @@ void ignoreleak(void)
// cppcheck-suppress memleak // cppcheck-suppress memleak
} }
void memleak_asprintf(char **ptr, const char *fmt, const int arg)
{
// No warning is expected for
if (-1 != asprintf(ptr,fmt,arg)) {
free(ptr);
}
if (-1 != asprintf(ptr,fmt,arg)) {
// TODO: Related to #8980 cppcheck-suppress memleak
}
}
void uninitvar__builtin_memset(void) void uninitvar__builtin_memset(void)
{ {
void *s; void *s;