Clang's scan-base warning fixes#85
Conversation
|
Commit 1: Fixes dead assignment at util.c, line 278. |
|
Commit 2: Fixes dead assignment at cmd.c, line 523 |
|
Commit 3: Fixes nonnull warning at util.c, line 542. Kinda stupid, I guess the static analyzer doesn't understand |
|
Commit 4: Fixes dead assignment at cmd.c, line 1621. |
|
Commit 5: Fixes dead assignment at buffer.c, line 1484. |
|
Commit 6: Fixes dead increment at cmd.c, line 1904. |
|
Commit 7: Fixes dead nested assignment at buffer.c, line 61. |
|
I have a question, If you look at these lines // Return a line given a line_index
int buffer_get_bline(buffer_t *self, bint_t line_index, bline_t **ret_bline) {
return buffer_get_bline_w_hint(self, line_index, self->first_line, ret_bline);
}
// Return a line given a line_index, starting at hint and iterating outward
int buffer_get_bline_w_hint(buffer_t *self, bint_t line_index, bline_t *opt_hint, bline_t **ret_bline) {
bline_t *fwd, *rev, *found;
MLBUF_MAKE_GT_EQ0(line_index);
if (!opt_hint) {
opt_hint = self->first_line;
}
fwd = opt_hint;
rev = opt_hint->prev;you see when this line is executed:
if (!opt_hint) {
opt_hint = self->first_line;
}Here if statement checks if I guess you just: return MLBUF_ERR; |
|
Yes, returning an error is OK in that case. diff --git a/buffer.c b/buffer.c
index d85466d..ee5a1dd 100644
--- a/buffer.c
+++ b/buffer.c
@@ -693,7 +693,7 @@ int buffer_replace_w_bline(buffer_t *self, bline_t *start_line, bint_t start_col
// Return a line given a line_index
int buffer_get_bline(buffer_t *self, bint_t line_index, bline_t **ret_bline) {
- return buffer_get_bline_w_hint(self, line_index, self->first_line, ret_bline);
+ return buffer_get_bline_w_hint(self, line_index, NULL, ret_bline);
}
// Return a line given a line_index, starting at hint and iterating outward
@@ -703,6 +703,10 @@ int buffer_get_bline_w_hint(buffer_t *self, bint_t line_index, bline_t *opt_hint
if (!opt_hint) {
opt_hint = self->first_line;
+ if (!opt_hint) {
+ *ret_bline = NULL;
+ return MLBUF_ERR;
+ }
}
fwd = opt_hint; |
|
Commit 8: Fixes potential null-pointer de-reference in buffer.c, line 709. |
|
Commit 9: Fixes potential null-pointer de-reference in editor.c, line 1518. |
|
Commit 10: Fixes potential null-pointer de-reference in editor.c, line 650. |
|
Commit 11: Fixes potential memory leak in editor.c, line 2272. |
|
Commit 12: Fixes potential zero size memory allocation in cmd.c, line 553. |
|
@proh14 Let me know when you'd like me to review / merge. No rush. Your call. Thank you again for your contributions. |
|
Hello :), I've been taking look at the last 3 problems but they all seem to be false flags that can't be really fixed. I will mark this ready for review so you can take a look at what I did. |
|
@adsr if you can please give it the hacktoberfest-accepted tag I need it for hacktoberfest |
|
Thanks again @proh14. I'll review soon. |
|
All merged. Just neatened 1 or 2 things up. Thank you again @proh14. |
Hello :-)
I'm working on all the warnings in this draft #84, each fix will be a single commit(tell me if you don't like that).
If you see any problems with the fixes, consider mentioning it here!