Skip to content

Commit cc8f3bf

Browse files
PatriciaBucatarukasper93
authored andcommitted
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.
1 parent e0f54ad commit cc8f3bf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

video/out/gpu/utils.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,12 @@ void mp_log_source(struct mp_log *log, int lev, const char *src)
339339
return;
340340
while (*src) {
341341
const char *end = strchr(src, '\n');
342-
const char *next = end + 1;
343-
if (!end)
342+
const char *next;
343+
if (!end) {
344344
next = end = src + strlen(src);
345+
} else {
346+
next = end + 1;
347+
}
345348
mp_msg(log, lev, "[%3d] %.*s\n", line, (int)(end - src), src);
346349
line++;
347350
src = next;

0 commit comments

Comments
 (0)