]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
split: avoid NULL + 1
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Sep 2021 20:44:46 +0000 (13:44 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Sep 2021 22:08:28 +0000 (15:08 -0700)
* src/split.c (lines_chunk_split): Don’t add to a null pointer.
It’s undefined behavior, and it’s unnecessarily confusing
regardless.

src/split.c

index f653e1b85b103b7488d4aedac910514f15e0acf2..6062f052a12e679b423aaec0f7a59dd35c908907 100644 (file)
@@ -921,8 +921,11 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
           /* Begin looking for '\n' at last byte of chunk.  */
           off_t skip = MIN (n_read, MAX (0, chunk_end - n_written));
           char *bp_out = memchr (bp + skip, eolchar, n_read - skip);
-          if (bp_out++)
-            next = true;
+          if (bp_out)
+            {
+              bp_out++;
+              next = true;
+            }
           else
             bp_out = eob;
           to_write = bp_out - bp;