The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=2171b2cbe084118e0e8f7de658f0302d0feb8827
commit 2171b2cbe084118e0e8f7de658f0302d0feb8827 Author: Piotr Pawel Stefaniak <ps...@freebsd.org> AuthorDate: 2021-09-05 16:59:08 +0000 Commit: Piotr Pawel Stefaniak <ps...@freebsd.org> CommitDate: 2021-09-15 23:46:44 +0000 diff: avoid applying offsets to null pointer This was the only instance of undefined behavior I could find so far. --- usr.bin/diff/diffreg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index c743c862f2d6..4a00aff9243b 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -255,7 +255,6 @@ diffreg(char *file1, char *file2, int flags, int capsicum) anychange = 0; lastline = 0; lastmatchline = 0; - context_vec_ptr = context_vec_start - 1; /* * hw excludes padding and make sure when -t is not used, @@ -1050,8 +1049,12 @@ proceed: /* * Allocate change records as needed. */ - if (context_vec_ptr == context_vec_end - 1) { - ptrdiff_t offset = context_vec_ptr - context_vec_start; + if (context_vec_start == NULL || + context_vec_ptr == context_vec_end - 1) { + ptrdiff_t offset = -1; + + if (context_vec_start != NULL) + offset = context_vec_ptr - context_vec_start; max_context <<= 1; context_vec_start = xreallocarray(context_vec_start, max_context, sizeof(*context_vec_start)); _______________________________________________ dev-commits-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"