summaryrefslogtreecommitdiff
path: root/src/csplit.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-07-28 02:21:07 +0100
committerPádraig Brady <P@draigBrady.com>2013-07-28 02:31:10 +0100
commit3ab87d254db5b12804d5bd49d38e63fb59c40f2b (patch)
tree63c14d3a558d47bb69c285969f5e95a74f3a0fab /src/csplit.c
parent012fbb63719f4a683604c4917a34d2039e38c023 (diff)
downloadcoreutils-3ab87d254db5b12804d5bd49d38e63fb59c40f2b.tar.xz
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.
Diffstat (limited to 'src/csplit.c')
-rw-r--r--src/csplit.c9
1 files 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 <config.h>
+#include <assert.h>
#include <getopt.h>
#include <sys/types.h>
#include <signal.h>
@@ -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. */