#include <stdio.h> int main() { char* test = NULL; test = malloc(5); return 0; } This gives with cppcheck --enable=all test.c --library=gnu.cfg test.c:9:5: error: Memory leak: test [memleak] return 0; ^ test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable] test = malloc(5); ^ But once I do: #include <stdio.h> int main() { char* test = NULL; test = malloc(5); (void) asprintf(&test, "%s_1", "test"); return 0; } This gives no errors, while I was expecting 2 leaks...
#include <stdio.h> int main() { char* test = NULL; test = malloc(5); return 0; } This gives with cppcheck --enable=all test.c --library=gnu.cfg test.c:9:5: error: Memory leak: test [memleak] return 0; ^ test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable] test = malloc(5); ^ But once I do: #include <stdio.h> int main() { char* test = NULL; test = malloc(5); (void) asprintf(&test, "%s_1", "test"); return 0; } This gives no errors, while I was expecting 2 leaks...
#include <stdio.h> int main() { char* test = NULL; test = malloc(5); return 0; } This gives with cppcheck --enable=all test.c --library=gnu.cfg test.c:9:5: error: Memory leak: test [memleak] return 0; ^ test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable] test = malloc(5); ^ But once I do: #include <stdio.h> int main() { char* test = NULL; test = malloc(5); (void) asprintf(&test, "%s_1", "test"); return 0; } This gives no errors, while I was expecting 2 leaks...
#include <stdio.h> int main() { char* test = NULL; test = malloc(5); return 0; } This gives with cppcheck --enable=all test.c --library=gnu.cfg test.c:9:5: error: Memory leak: test [memleak] return 0; ^ test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable] test = malloc(5); ^ But once I do: #include <stdio.h> int main() { char* test = NULL; test = malloc(5); (void) asprintf(&test, "%s_1", "test"); return 0; } This gives no errors, while I was expecting 2 leaks...
Hi, I am not sure this is already tracked by a bug ticket. GCC and cppcheck do not detect that entries_bad_format is used as unitialized variable in case of for loops not being executed. Simplified code snippet: #include <stdio.h> #include <stdbool.h> int main() { bool entries_bad_format; unsigned int n_entries = 0; // In real example can be assigned by anything mostly > 0 but could be 0 (json_array_size) for (size_t i = 0; i < n_entries; i++) { entries_bad_format = true; } if(entries_bad_format)...
Sorry for the inconvenience. Apparantly I was running it with 1.90, indeed on 2.4.1 this particular simplified case above is fixed. In our case the n_entries is filled in by size_t json_array_size(const json_t *array (jansson lib) and as cppcheck does not know that lib (no lib cfg yet) it fails to find it propably?
Hi, I am not sure this is already tracked by a bug ticket. GCC and cppcheck do not detect that entries_bad_format is used as unitialized variable in case of for loops not being executed. Simplified code snippet: #include <stdio.h> #include <stdbool.h> int main() { bool entries_bad_format; unsigned int n_entries = 0; // In real example can be assigned by anything mostly > 0 but could be 0 for (size_t i = 0; i < n_entries; i++) { entries_bad_format = true; } if(entries_bad_format) printf("hello");...