]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: avoid new coverity warnings
authorPádraig Brady <P@draigBrady.com>
Fri, 29 May 2015 14:33:59 +0000 (15:33 +0100)
committerPádraig Brady <P@draigBrady.com>
Fri, 29 May 2015 23:41:09 +0000 (00:41 +0100)
* 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.

src/dd.c
src/factor.c
src/head.c
src/ls.c
src/od.c
src/sync.c
src/tac.c

index 6b09bc6452327736381c6e98809822dc95118e30..e64729477101f471a31adcb6582d03d2274499cf 100644 (file)
--- 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)
                 {
index 4e4d0c7cbeb329858a37307066b584b15d96ca6f..f27bf22f250b9d87b9b1f40400b1caf0fd11311e 100644 (file)
@@ -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
index 3ea81b65150e0c1626cc266332f5733dfe76e215..410cc4f4936b52f2ecab9719d02aa6f546abd178 100644 (file)
@@ -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
     {
index 01404e25cd8c4fca12d0adb1b26e379698b2fe59..6860dd413651e88715bf4387887c36d0ff3273a4 100644 (file)
--- 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.  */
index c1241f54102f3b3d5a4150edbd06b5da85c28309..0ca3ca7871525ed2e4e91d4d5131fa33971f9a89 100644 (file)
--- 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;
index b71b8bc21a7c835468844503d55dd9adb4b36d4f..85d77c092ae9fe9bb1ba7a1f759fdab14a4d00f1 100644 (file)
@@ -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)
         {
index 2d73c6e78bcec65d4d45b6121a0038d2d9896e49..57e7e761d3a5c7af419380175e749ae15b873c22 100644 (file)
--- 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;
             }