gpu/utils: fix null pointer arithmetic UB in mp_log_source

strchr() can return NULL when no newline is found. Computing end + 1
before the null check on end is undefined behaviour per C11 6.5.6.
Move the next assignment inside the else branch to avoid the UB.
This commit is contained in:
Patricia Bucataru authored and Kacper Michajłow committed 2026-04-17 19:11:58 +02:00
1 parent e0f54adf08
commit cc8f3bf9fa
1 file changed
+5 -2
+5 -2
View File
@@ -339,9 +339,12 @@ void mp_log_source(struct mp_log *log, int lev, const char *src)
return;
while (*src) {
const char *end = strchr(src, '\n');
const char *next = end + 1;
if (!end)
const char *next;
if (!end) {
next = end = src + strlen(src);
} else {
next = end + 1;
}
mp_msg(log, lev, "[%3d] %.*s\n", line, (int)(end - src), src);
line++;
src = next;