Skip to content

Commit

Permalink
Bug 1302233 - Introduce VsprintfLiteral to mfbt. r=froydnj
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Sep 14, 2016
1 parent 8122a0d commit c8fdd1e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mfbt/Sprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
#include <stdio.h>
#include <stdarg.h>

#include "mozilla/Assertions.h"

#ifdef __cplusplus

template <size_t N>
int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args)
{
MOZ_ASSERT(format != buffer);
int result = vsnprintf(buffer, N, format, args);
buffer[N - 1] = '\0';
return result;
}

template <size_t N>
#if defined(__GNUC__)
__attribute__((format(printf, 2, 3)))
Expand All @@ -21,11 +33,10 @@ int SprintfLiteral(char (&buffer)[N], const char* format, ...)
{
va_list args;
va_start(args, format);
int result = vsnprintf(buffer, N, format, args);
int result = VsprintfLiteral(buffer, format, args);
va_end(args);
buffer[N - 1] = '\0';
return result;
}
#endif

#endif
#endif /* mozilla_Sprintf_h_ */

0 comments on commit c8fdd1e

Please sign in to comment.