From ad05e76c57820eb93a21f8e4185f36f58ec2c1fc Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 20 Dec 2013 21:07:16 +0100 Subject: msg: handle vsnprintf errors I don't know under which circumstances this can error (other than a broken format string). It seems it won't return an error code on I/O errors, so maybe broken format strings are the only case. Either way, don't continue if an error is returned. --- common/msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common/msg.c') diff --git a/common/msg.c b/common/msg.c index 6d4e374a24..926d9f06fc 100644 --- a/common/msg.c +++ b/common/msg.c @@ -155,7 +155,8 @@ void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va) FILE *stream = (mp_msg_stdout_in_use || lev == MSGL_STATUS) ? stderr : stdout; char tmp[MSGSIZE_MAX]; - vsnprintf(tmp, MSGSIZE_MAX, format, va); + if (vsnprintf(tmp, MSGSIZE_MAX, format, va) < 0) + snprintf(tmp, MSGSIZE_MAX, "[fprintf error]\n"); tmp[MSGSIZE_MAX - 2] = '\n'; tmp[MSGSIZE_MAX - 1] = 0; -- cgit v1.2.3