This revision was automatically updated to reflect the committed changes. Closed by commit rG5a2e595eb833: [analyzer] Fix Static Analyzer g_memdup false-positive (authored by steakhal).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124436/new/ https://reviews.llvm.org/D124436 Files: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/test/Analysis/gmalloc.c Index: clang/test/Analysis/gmalloc.c =================================================================== --- clang/test/Analysis/gmalloc.c +++ clang/test/Analysis/gmalloc.c @@ -21,6 +21,7 @@ gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes); void g_free(gpointer mem); gpointer g_memdup(gconstpointer mem, guint byte_size); +gpointer g_strconcat(gconstpointer string1, ...); static const gsize n_bytes = 1024; @@ -167,3 +168,16 @@ g_free(g6); g_free(g7); } + +void f8(void) { + typedef struct { + gpointer str; + } test_struct; + + test_struct *s1 = (test_struct *)g_malloc0(sizeof(test_struct)); + test_struct *s2 = (test_struct *)g_memdup(s1, sizeof(test_struct)); + gpointer str = g_strconcat("text", s1->str, s2->str, NULL); // no-warning + g_free(str); + g_free(s2); + g_free(s1); +} Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1408,8 +1408,8 @@ void MallocChecker::checkGMemdup(const CallEvent &Call, CheckerContext &C) const { ProgramStateRef State = C.getState(); - State = MallocMemAux(C, Call, Call.getArgExpr(1), UndefinedVal(), State, - AF_Malloc); + State = + MallocMemAux(C, Call, Call.getArgExpr(1), UnknownVal(), State, AF_Malloc); State = ProcessZeroAllocCheck(Call, 1, State); C.addTransition(State); }
Index: clang/test/Analysis/gmalloc.c =================================================================== --- clang/test/Analysis/gmalloc.c +++ clang/test/Analysis/gmalloc.c @@ -21,6 +21,7 @@ gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes); void g_free(gpointer mem); gpointer g_memdup(gconstpointer mem, guint byte_size); +gpointer g_strconcat(gconstpointer string1, ...); static const gsize n_bytes = 1024; @@ -167,3 +168,16 @@ g_free(g6); g_free(g7); } + +void f8(void) { + typedef struct { + gpointer str; + } test_struct; + + test_struct *s1 = (test_struct *)g_malloc0(sizeof(test_struct)); + test_struct *s2 = (test_struct *)g_memdup(s1, sizeof(test_struct)); + gpointer str = g_strconcat("text", s1->str, s2->str, NULL); // no-warning + g_free(str); + g_free(s2); + g_free(s1); +} Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1408,8 +1408,8 @@ void MallocChecker::checkGMemdup(const CallEvent &Call, CheckerContext &C) const { ProgramStateRef State = C.getState(); - State = MallocMemAux(C, Call, Call.getArgExpr(1), UndefinedVal(), State, - AF_Malloc); + State = + MallocMemAux(C, Call, Call.getArgExpr(1), UnknownVal(), State, AF_Malloc); State = ProcessZeroAllocCheck(Call, 1, State); C.addTransition(State); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits