Skip to content

Commit d4e906f

Browse files
authored
Merge pull request #2803 from seanm/UBSan-utf8
Fixed various UBSan warnings about working with NULL pointers
2 parents d7b6ad0 + 23aa46f commit d4e906f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

libdispatch/utf8proc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_
355355
for (; len >= 0; entry++, len--) {
356356
nc_utf8proc_int32_t entry_cp = nc_seqindex_decode_entry(&entry);
357357

358-
written += nc_utf8proc_decompose_char(entry_cp, dst+written,
358+
nc_utf8proc_int32_t *dest = dst ? (dst+written) : NULL;
359+
written += nc_utf8proc_decompose_char(entry_cp, dest,
359360
(bufsize > written) ? (bufsize - written) : 0, options,
360361
last_boundclass);
361362
if (written < 0) return UTF8PROC_ERROR_OVERFLOW;
@@ -525,8 +526,10 @@ static nc_utf8proc_ssize_t nc_seqindex_write_char_decomposed(nc_utf8proc_uint16_
525526
if (custom_func != NULL) {
526527
uc = custom_func(uc, custom_data); /* user-specified custom mapping */
527528
}
529+
nc_utf8proc_int32_t *dest = NULL;
530+
if (buffer) dest = buffer + wpos;
528531
decomp_result = nc_utf8proc_decompose_char(
529-
uc, buffer + wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options,
532+
uc, dest, (bufsize > wpos) ? (bufsize - wpos) : 0, options,
530533
&boundclass
531534
);
532535
if (decomp_result < 0) return decomp_result;

0 commit comments

Comments
 (0)