Fix #7504: posix: open() was twice in configuration file (#1032)

* Fix #7504: posix: open() was twice in configuration file

This fixes ticket #7504: Problems with the open function were not always
detected because the open function was twice in posix.cfg and only the
second configuration was used by cppcheck. Like suggested now only
one configuration is used and the third parameter has a default value
and is thereby optional.
use-retval has been removed to avoid duplicate warnings because the
alloc/dealloc configuration already warns about unused retval.
According tests to verify that open is configured
correctly now have been added to test/cfg/posix.c.

* posix.cfg: open(): Add TODO for use-retval configuration
This commit is contained in:
Sebastian 2018-01-18 13:56:36 +01:00 committed by Daniel Marjamäki
parent 8878e6dd0d
commit de7aa8f513
2 changed files with 27 additions and 14 deletions

View File

@ -242,21 +242,10 @@
</arg>
</function>
<!-- int open(const char *pathname, int flags) -->
<function name="open">
<use-retval/>
<returnValue type="int"/>
<noreturn>false</noreturn>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
</function>
<!-- int open(const char *pathname, int flags, mode_t mode); -->
<function name="open">
<use-retval/>
<!-- TODO: add use-retval when cppcheck suppresses redundant messages
because of violations to alloc/dealloc and use-retval configuration-->
<returnValue type="int"/>
<noreturn>false</noreturn>
<arg nr="1">
@ -266,7 +255,7 @@
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<arg nr="3" default="0">
<not-uninit/>
</arg>
</function>

View File

@ -62,6 +62,12 @@ void nullPointer(char *p, int fd)
// not implemented yet: cppcheck-suppress nullPointer
write(fd,NULL,42);
write(fd,NULL,0);
// cppcheck-suppress leakReturnValNotUsed
// cppcheck-suppress nullPointer
open(NULL, 0);
// cppcheck-suppress leakReturnValNotUsed
// cppcheck-suppress nullPointer
open(NULL, 0, 0);
}
void memleak_getaddrinfo()
@ -107,6 +113,20 @@ void resourceLeak_socket(void)
// cppcheck-suppress resourceLeak
}
void resourceLeak_open1(void)
{
// cppcheck-suppress unreadVariable
int fd = open("file", O_RDWR | O_CREAT);
// cppcheck-suppress resourceLeak
}
void resourceLeak_open2(void)
{
// cppcheck-suppress unreadVariable
int fd = open("file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
// cppcheck-suppress resourceLeak
}
void noleak(int x, int y, int z)
{
DIR *p1 = fdopendir(x);
@ -115,6 +135,10 @@ void noleak(int x, int y, int z)
closedir(p2);
int s = socket(AF_INET,SOCK_STREAM,0);
close(s);
int fd1 = open("a", O_RDWR | O_CREAT);
close(fd1);
int fd2 = open("a", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
close(fd2);
/* TODO: add configuration for open/fdopen
// #2830
int fd = open("path", O_RDONLY);