From b7f5cde4e3a19d4afd2544b2efc10112092d5d13 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sat, 8 Aug 2020 10:41:24 +0200 Subject: [PATCH] libobs: Fix undefined behavior It is undefined behavior to apply an offset to a null pointer. I would have liked to reference cppreference but best I found was the PR that added this check to clang's undefined behavior sanitizer: https://reviews.llvm.org/D67122 . --- libobs/util/utf8.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libobs/util/utf8.c b/libobs/util/utf8.c index 526f81c8a..3f8aadfc7 100644 --- a/libobs/util/utf8.c +++ b/libobs/util/utf8.c @@ -110,7 +110,7 @@ static int utf8_forbidden(unsigned char octet) * * It takes the following arguments: * in - input UTF-8 string. It can be null-terminated. - * insize - size of input string in bytes. If insize is 0, + * insize - size of input string in bytes. If insize is 0, * function continues until a null terminator is reached. * out - result buffer for UCS-4 string. If out is NULL, * function returns size of result buffer. @@ -143,7 +143,7 @@ size_t utf8_to_wchar(const char *in, size_t insize, wchar_t *out, total = 0; p = (unsigned char *)in; lim = (insize != 0) ? (p + insize) : (unsigned char *)-1; - wlim = out + outsize; + wlim = out == NULL ? NULL : out + outsize; for (; p < lim; p += n) { if (!*p) @@ -272,7 +272,7 @@ size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, w = (wchar_t *)in; wlim = (insize != 0) ? (w + insize) : (wchar_t *)-1; p = (unsigned char *)out; - lim = p + outsize; + lim = out == NULL ? NULL : p + outsize; total = 0; for (; w < wlim; w++) {