From 049c353f52f406ee12d032dd0a03e755c472ea2b Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Tue, 26 Apr 2016 15:08:46 -0700 Subject: [PATCH] Add a model for gzdopen Summary: Add model for gzdopen Reviewed By: ddino Differential Revision: D3223727 fb-gh-sync-id: a4d55fb fbshipit-source-id: a4d55fb --- infer/models/c/src/libc_basic.c | 3 +++ .../codetoanalyze/c/errors/resource_leaks/leak.c | 16 ++++++++++++++++ infer/tests/endtoend/c/ResourceLeakTest.java | 5 ++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/infer/models/c/src/libc_basic.c b/infer/models/c/src/libc_basic.c index c52aa845a..e636e5df1 100644 --- a/infer/models/c/src/libc_basic.c +++ b/infer/models/c/src/libc_basic.c @@ -494,6 +494,9 @@ FILE* fdopen(int fildes, const char* mode) { return fopen("foo", mode); } +// modeled using fdopen +FILE* gzdopen(int fildes, const char* mode) { return fdopen(fildes, mode); } + // return nonteterministically 0 or -1 // requires stream to be allocated int fseek(FILE* stream, long int offset, int whence) { diff --git a/infer/tests/codetoanalyze/c/errors/resource_leaks/leak.c b/infer/tests/codetoanalyze/c/errors/resource_leaks/leak.c index 55caa574e..2132b646c 100644 --- a/infer/tests/codetoanalyze/c/errors/resource_leaks/leak.c +++ b/infer/tests/codetoanalyze/c/errors/resource_leaks/leak.c @@ -39,6 +39,22 @@ void fileClosed() { } } +FILE* handler; + +void fdopen_example() { + int fd = open("hi.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd != -1) { + handler = fdopen(fd, "w"); + } +} + +void gzdopen_example() { + int fd = open("hi.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd != -1) { + handler = gzdopen(fd, "w"); + } +} + void socketNotClosed() { int fd = socket(AF_LOCAL, SOCK_RAW, 0); if (fd != -1) { diff --git a/infer/tests/endtoend/c/ResourceLeakTest.java b/infer/tests/endtoend/c/ResourceLeakTest.java index 674f7a4ab..a46d99ffc 100644 --- a/infer/tests/endtoend/c/ResourceLeakTest.java +++ b/infer/tests/endtoend/c/ResourceLeakTest.java @@ -10,7 +10,7 @@ package endtoend.c; import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsTheseErrors.contains; +import static utils.matchers.ResultContainsExactly.containsExactly; import org.junit.BeforeClass; import org.junit.Test; @@ -41,11 +41,10 @@ public class ResourceLeakTest { "fileNotClosed", "socketNotClosed" }; - assertThat( "Results should contain " + RESOURCE_LEAK, inferResults, - contains( + containsExactly( RESOURCE_LEAK, SOURCE_FILE, functions