From 23aa46fcf51437de23a83862427acb605a8a8740 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 15 Nov 2023 15:11:56 -0500 Subject: [PATCH] Fixed various UBSan warnings about working with NULL pointers Any pointer arithmetic with NULL pointers is technically UB, even if you don't end up dereferencing the pointer. --- libdispatch/utf8proc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libdispatch/utf8proc.c b/libdispatch/utf8proc.c index 3a05dd3b3..68d8dd4a2 100644 --- a/libdispatch/utf8proc.c +++ b/libdispatch/utf8proc.c @@ -355,7 +355,8 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_ for (; len >= 0; entry++, len--) { nc_utf8proc_int32_t entry_cp = nc_seqindex_decode_entry(&entry); - written += nc_utf8proc_decompose_char(entry_cp, dst+written, + nc_utf8proc_int32_t *dest = dst ? (dst+written) : NULL; + written += nc_utf8proc_decompose_char(entry_cp, dest, (bufsize > written) ? (bufsize - written) : 0, options, last_boundclass); if (written < 0) return UTF8PROC_ERROR_OVERFLOW; @@ -525,8 +526,10 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_ if (custom_func != NULL) { uc = custom_func(uc, custom_data); /* user-specified custom mapping */ } + nc_utf8proc_int32_t *dest = NULL; + if (buffer) dest = buffer + wpos; decomp_result = nc_utf8proc_decompose_char( - uc, buffer + wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options, + uc, dest, (bufsize > wpos) ? (bufsize - wpos) : 0, options, &boundclass ); if (decomp_result < 0) return decomp_result;