From f8dc5a6215846f289d9e9c4c18a7c51f008f76d3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 15 Sep 2021 13:44:46 -0700 Subject: [PATCH] split: avoid NULL + 1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/split.c b/src/split.c index f653e1b85b..6062f052a1 100644 --- a/src/split.c +++ b/src/split.c @@ -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; -- 2.47.2