Skip to content

Commit

Permalink
Bug 798873 Patch 3 - flex_string fix for Windows vsnprintf r=jesup a=…
Browse files Browse the repository at this point in the history
…bajaj
  • Loading branch information
ethanhugg committed Oct 18, 2012
1 parent d80a54a commit 45eec6f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions media/webrtc/signaling/src/sipcc/cpr/common/cpr_string.c
Expand Up @@ -213,6 +213,14 @@ void flex_string_sprintf(flex_string *fs, const char *format, ...) {
vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap);
va_end(ap);

/* Special case just for Windows where vsnprintf is broken
and returns -1 if buffer too large unless you size it 0. */
if (vsnprintf_result < 0) {
va_start(ap, format);
vsnprintf_result = vsnprintf(NULL, 0, format, ap);
va_end(ap);
}

if (fs->string_length + vsnprintf_result >= fs->buffer_length) {
/* Buffer overflow, resize */
flex_string_check_alloc(fs, fs->string_length + vsnprintf_result + 1);
Expand Down

0 comments on commit 45eec6f

Please sign in to comment.