[FFmpeg-devel] [PATCH 2/2] compat/vsnprintf: return number of bytes required on truncation.
Derek Buitenhuis
derek.buitenhuis at gmail.com
Fri Sep 14 21:08:20 CEST 2012
From: "Ronald S. Bultje" <rsbultje at gmail.com>
This conforms to C99, but requires Windows >= XP.
---
compat/msvcrt/snprintf.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/compat/msvcrt/snprintf.c b/compat/msvcrt/snprintf.c
index 36f6dd1..244e1e9 100644
--- a/compat/msvcrt/snprintf.c
+++ b/compat/msvcrt/snprintf.c
@@ -43,9 +43,10 @@ int avpriv_vsnprintf(char *s, size_t n, const char *fmt,
va_list ap)
{
int ret;
+ va_list ap_copy;
if (n == 0)
- return 0;
+ return _vscprintf(fmt, ap);
else if (n > INT_MAX)
return AVERROR(EOVERFLOW);
@@ -57,8 +58,11 @@ int avpriv_vsnprintf(char *s, size_t n, const char *fmt,
* See http://msdn.microsoft.com/en-us/library/1kt27hek(v=vs.80).aspx */
memset(s, 0, n);
ret = _vsnprintf(s, n - 1, fmt, ap);
- if (ret == -1)
- ret = n;
+ if (ret == -1) {
+ va_copy(ap_copy, ap);
+ ret = _vscprintf(fmt, ap);
+ va_end(ap_copy);
+ }
return ret;
}
--
1.7.9.5
More information about the ffmpeg-devel
mailing list