From: Pádraig Brady
Date: Sun, 28 Jul 2013 01:21:07 +0000 (+0100)
Subject: maint: avoid clang static analysis issues in csplit
X-Git-Tag: v8.22~96
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ab87d254db5b12804d5bd49d38e63fb59c40f2b;p=thirdparty%2Fcoreutils.git
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.
---
diff --git a/src/csplit.c b/src/csplit.c
index 7a36e67366..5bfca09b52 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. */