posix.cfg: Added partial support for scandir() and a TODO comment.

This commit is contained in:
orbitcowboy 2019-05-25 23:32:28 +02:00
parent 4d223a70dc
commit 02d307a231
2 changed files with 62 additions and 0 deletions

View File

@ -4026,6 +4026,32 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
<not-bool/>
</arg>
</function>
<!-- http://man7.org/linux/man-pages/man3/scandir.3.html -->
<!-- int scandir(const char *dirp,
struct dirent ***namelist,
int (*filter)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));-->
<function name="scandir">
<use-retval/>
<returnValue type="int"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
<not-null/>
<not-uninit/>
</arg>
<arg nr="2" direction="out">
<not-null/>
</arg>
<arg nr="3" direction="in">
<not-uninit/>
</arg>
<arg nr="4" direction="in">
<not-uninit/>
<not-null/>
<not-bool/>
</arg>
</function>
<!-- http://man7.org/linux/man-pages/man3/fileno.3p.html -->
<!-- int fileno(FILE *stream); -->
<function name="fileno">
@ -4863,6 +4889,10 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
<alloc init="false" arg="1">posix_memalign</alloc>
<dealloc>free</dealloc>
</memory>
<memory>
<alloc init="false" arg="2">scandir</alloc>
<dealloc>free</dealloc>
</memory>
<memory>
<alloc init="true" buffer-size="strdup">strdup</alloc>
<alloc init="true">strndup</alloc>

View File

@ -21,6 +21,38 @@
#include <unistd.h>
#include <pthread.h>
void memleak_scandir(void)
{
struct dirent **namelist;
int n = scandir(".", &namelist, NULL, alphasort);
if (n == -1) {
return;
}
// http://man7.org/linux/man-pages/man3/scandir.3.html
/* The scandir() function scans the directory dirp, calling filter() on
each directory entry. Entries for which filter() returns nonzero are
stored in strings allocated via malloc(3), sorted using qsort(3) with
the comparison function compar(), and collected in array namelist
which is allocated via malloc(3). If filter is NULL, all entries are
selected.*/
// TODO: cppcheck-suppress memleak
}
void no_memleak_scandir(void)
{
struct dirent **namelist;
int n = scandir(".", &namelist, NULL, alphasort);
if (n == -1) {
return;
}
while (n--) {
free(namelist[n]);
}
free(namelist);
}
void validCode()
{
void *ptr;