From 3ab87d254db5b12804d5bd49d38e63fb59c40f2b Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Sun, 28 Jul 2013 02:21:07 +0100 Subject: [PATCH] maint: avoid clang static analysis issues in csplit * src/csplit.c (find_lines): Assert that load_buffer() updates the global buffers, thus "b" will be non NULL, thus suppressing subsequent NULL pointer derefence warnings. (process_regexp): Avoid a redundant assignment of the "line" pointer. (process_line_count): Likewise. Also reduce the "line" pointer scope. --- src/csplit.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/csplit.c b/src/csplit.c index 7a36e6736..5bfca09b5 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -612,6 +613,7 @@ find_line (uintmax_t linenum) for (b = head;;) { + assert (b); if (linenum < b->start_line + b->num_lines) { /* The line is in this buffer. */ @@ -728,7 +730,6 @@ process_line_count (const struct control *p, uintmax_t repetition) { uintmax_t linenum; uintmax_t last_line_to_save = p->lines_required * (repetition + 1); - struct cstring *line; create_output_file (); @@ -741,7 +742,7 @@ process_line_count (const struct control *p, uintmax_t repetition) linenum = get_first_line_in_buffer (); while (linenum++ < last_line_to_save) { - line = remove_line (); + struct cstring *line = remove_line (); if (line == NULL) handle_line_error (p, repetition); save_line_to_file (line); @@ -750,7 +751,7 @@ process_line_count (const struct control *p, uintmax_t repetition) close_output_file (); if (suppress_matched) - line = remove_line (); + remove_line (); /* Ensure that the line number specified is not 1 greater than the number of lines in the file. */ @@ -798,7 +799,7 @@ process_regexp (struct control *p, uintmax_t repetition) create_output_file (); if (suppress_matched && current_line > 0) - line = remove_line (); + remove_line (); /* If there is no offset for the regular expression, or it is positive, then it is not necessary to buffer the lines. */ -- 2.11.4.GIT