From 630a0e7eac8ed108d39d06d24f324995c97bb907 Mon Sep 17 00:00:00 2001 From: Patricia Bucataru Date: Wed, 8 Apr 2026 04:49:21 +0300 Subject: [PATCH] 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. --- video/out/gpu/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/video/out/gpu/utils.c b/video/out/gpu/utils.c index 0377a4a9f8932..0ef2a19b842c1 100644 --- a/video/out/gpu/utils.c +++ b/video/out/gpu/utils.c @@ -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;