summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-05-29 15:33:59 +0100
committerPádraig Brady <P@draigBrady.com>2015-05-30 00:41:09 +0100
commitb9842a615366b47cbd0739d97f2dd2679dfbb3a8 (patch)
treec272db54a8a0539db3f6eb6416cf6c422bf8e1f2 /src
parent17621b594a74af2cf77a7120b89add47397dbd11 (diff)
downloadcoreutils-b9842a615366b47cbd0739d97f2dd2679dfbb3a8.tar.xz
maint: avoid new coverity warnings
* src/sync.c (sync_arg): Initialise variable to avoid unitialized access if assert is disabled. * src/head.c (elide_tail_bytes_file): Support this function with ---presume-input-pipe and larger files, which regressed with commit v8.23-47-g2662702. (elide_tail_lines_file): Likewise. * src/dd.c (dd_copy): Explicitly don't try to ftruncate() upon failure to lseek() (the existing check against st_size was already protecting that). * src/factor.c (factor_using_squfof): Assert (only when linting due to performance) to avoid the implication of divide by zero. * src/od.c (read_block): Remove dead code. * src/tac.c (tac_seekable): Likewise. * src/ls.c (gobble_file): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/dd.c2
-rw-r--r--src/factor.c3
-rw-r--r--src/head.c4
-rw-r--r--src/ls.c1
-rw-r--r--src/od.c3
-rw-r--r--src/sync.c2
-rw-r--r--src/tac.c5
7 files changed, 6 insertions, 14 deletions
diff --git a/src/dd.c b/src/dd.c
index 6b09bc645..e64729477 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -2280,7 +2280,7 @@ dd_copy (void)
if (S_ISREG (stdout_stat.st_mode) || S_TYPEISSHM (&stdout_stat))
{
off_t output_offset = lseek (STDOUT_FILENO, 0, SEEK_CUR);
- if (output_offset > stdout_stat.st_size)
+ if (0 <= output_offset && stdout_stat.st_size < output_offset)
{
if (iftruncate (STDOUT_FILENO, output_offset) != 0)
{
diff --git a/src/factor.c b/src/factor.c
index 4e4d0c7cb..f27bf22f2 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -2055,8 +2055,9 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
div_smallq (q, rem, S+P, Q);
P1 = S - rem; /* P1 = q*Q - P */
+ IF_LINT (assert (q > 0 && Q > 0));
+
#if STAT_SQUFOF
- assert (q > 0);
q_freq[0]++;
q_freq[MIN (q, Q_FREQ_SIZE)]++;
#endif
diff --git a/src/head.c b/src/head.c
index 3ea81b651..410cc4f49 100644
--- a/src/head.c
+++ b/src/head.c
@@ -458,7 +458,7 @@ elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide,
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (size <= ST_BLKSIZE (*st))
+ if (presume_input_pipe || size <= ST_BLKSIZE (*st))
return elide_tail_bytes_pipe (filename, fd, n_elide, current_pos);
else
{
@@ -747,7 +747,7 @@ elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide,
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (size <= ST_BLKSIZE (*st))
+ if (presume_input_pipe || size <= ST_BLKSIZE (*st))
return elide_tail_lines_pipe (filename, fd, n_elide, current_pos);
else
{
diff --git a/src/ls.c b/src/ls.c
index 01404e25c..6860dd413 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2947,7 +2947,6 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
|| ((print_inode || format_needs_type)
&& (type == symbolic_link || type == unknown)
&& (dereference == DEREF_ALWAYS
- || (command_line_arg && dereference != DEREF_NEVER)
|| color_symlink_as_referent || check_symlink_color))
/* Command line dereferences are already taken care of by the above
assertion that the inode number is not yet known. */
diff --git a/src/od.c b/src/od.c
index c1241f541..0ca3ca787 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1291,9 +1291,6 @@ read_block (size_t n, char *block, size_t *n_bytes_in_buffer)
*n_bytes_in_buffer = 0;
- if (n == 0)
- return true;
-
while (in_stream != NULL) /* EOF. */
{
size_t n_needed;
diff --git a/src/sync.c b/src/sync.c
index b71b8bc21..85d77c092 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -117,7 +117,7 @@ sync_arg (enum sync_mode mode, char const *file)
if (ret == true)
{
- int sync_status;
+ int sync_status = -1;
switch (mode)
{
diff --git a/src/tac.c b/src/tac.c
index 2d73c6e78..57e7e761d 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -321,8 +321,6 @@ tac_seekable (int input_fd, const char *file, off_t file_pos)
'G_buffer_size'. */
char *newbuffer;
size_t offset = sentinel_length ? sentinel_length : 1;
- ptrdiff_t match_start_offset = match_start - G_buffer;
- ptrdiff_t past_end_offset = past_end - G_buffer;
size_t old_G_buffer_size = G_buffer_size;
read_size *= 2;
@@ -331,9 +329,6 @@ tac_seekable (int input_fd, const char *file, off_t file_pos)
xalloc_die ();
newbuffer = xrealloc (G_buffer - offset, G_buffer_size);
newbuffer += offset;
- /* Adjust the pointers for the new buffer location. */
- match_start = newbuffer + match_start_offset;
- past_end = newbuffer + past_end_offset;
G_buffer = newbuffer;
}