You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing C we must ensure we code safely, especially with memory functions, i.e. we don't use-after-free or double-free or null-dereference...
Tools to help discover these issues exist, e.g. splint, cppcheck, infer...
Here is a run of infer against your codebase:
$ infer run -- make
Capturing in make/cc mode...
Found 9 source files to analyze in /dir/viw/infer-out
Starting analysis...
legend:
"F" analyzing a file
"." analyzing a procedure
FFFFFFFF...............................F..............................................................................
Found 14 issues
src/buffer.c:40: error: NULL_DEREFERENCE
pointer `ec` last assigned on line 36 could be null and is dereferenced at line 40, column 3
38. echar_t *prev = NULL;
39.
40. > ec->c = c;
41. ec->prev = NULL;
42. ec->next = NULL;
src/buffer.c:113: error: NULL_DEREFERENCE
pointer `buf` last assigned on line 111 could be null and is dereferenced at line 113, column 3
111. buffer_t *buf = malloc(sizeof(buffer_t));
112.
113. > buf->num_rows = 0;
114. buf->head = NULL;
115. buf->last = NULL;
<...SNIP...>
Summary of the reports
NULL_DEREFERENCE: 14
(Most issues detected by infer here are due to not checking if malloc failed, but there is one where a fopen is not checked either.)
I suggest you employ some static analyzers to help you check your code as part of your regular development process (and before accepting PRs). Good luck!
When writing C we must ensure we code safely, especially with memory functions, i.e. we don't use-after-free or double-free or null-dereference...
Tools to help discover these issues exist, e.g. splint, cppcheck, infer...
Here is a run of infer against your codebase:
(Most issues detected by infer here are due to not checking if malloc failed, but there is one where a fopen is not checked either.)
I suggest you employ some static analyzers to help you check your code as part of your regular development process (and before accepting PRs). Good luck!
Links:
The text was updated successfully, but these errors were encountered: