Skip to content

Commit

Permalink
av_log_ug_callback: handle overflow
Browse files Browse the repository at this point in the history
If the buffer is full, flush the output even if there is no NL at the
end and issue a warning (should be handled - either some error or some
module produces unexpectedly long output).
  • Loading branch information
MartinPulec committed Nov 1, 2023
1 parent fea0d10 commit 9938f6b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libavcodec/lavc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,14 @@ static void av_log_ug_callback(void *avcl, int av_level, const char *fmt, va_lis
snprintf(buf + strlen(buf), sizeof buf - strlen(buf), "] ");
}
vsnprintf(buf + strlen(buf), sizeof buf - strlen(buf), fmt, vl);
if (buf[strlen(buf) - 1] == '\n') {
log_msg(level, "%s", buf);
buf[0] = '\0';
if (buf[strlen(buf) - 1] != '\n' && strlen(buf) < sizeof buf - 1) {
return;
}
if (strlen(buf) == sizeof buf - 1 && buf[strlen(buf) - 1] != '\n') {
MSG(WARNING, "logger buffer full! flushing output:\n");
}
log_msg(level, "%s", buf);
buf[0] = '\0';
}

ADD_TO_PARAM("lavcd-log-level",
Expand Down

0 comments on commit 9938f6b

Please sign in to comment.