From de7aa8f5134a4b666ce642f3108ae3121f77905b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 18 Jan 2018 13:56:36 +0100 Subject: [PATCH] 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 --- cfg/posix.cfg | 17 +++-------------- test/cfg/posix.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/cfg/posix.cfg b/cfg/posix.cfg index 4af5564f3..fe86474e5 100644 --- a/cfg/posix.cfg +++ b/cfg/posix.cfg @@ -242,21 +242,10 @@ - - - - false - - - - - - - - - + false @@ -266,7 +255,7 @@ - + diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 40c8c9001..15227a160 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -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);