diff --git a/src/lxc/log.c b/src/lxc/log.c index cab77f24c..6775822b3 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -170,10 +170,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender, event->locinfo->file, event->locinfo->func, event->locinfo->line); - n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, - *event->vap); + if (n < 0) + return n; - if (n >= sizeof(buffer) - 1) { + if (n < sizeof(buffer) - 1) + n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, + *event->vap); + else { WARN("truncated next event from %d to %zd bytes", n, sizeof(buffer)); n = sizeof(buffer) - 1;