Bug 1277155 - Part 1: Remove snprintf() polyfills for VS2013 in Sprintf.h and #defines. r=froydnj r=mhowell
authorChris Peterson <cpeterson@mozilla.com>
Mon, 27 Jun 2016 20:45:03 -0700
changeset 384981 3f99486c6b0157f468e0bc76bdc2348daf158541
parent 384980 35839591031515b8e08a3a63ce84e27fdcde9390
child 384982 9e0a6eedc2b6b2c24b67b356b8ab0de57af33abf
push id22385
push userbmo:wpan@mozilla.com
push dateThu, 07 Jul 2016 12:18:17 +0000
reviewersfroydnj, mhowell
bugs1277155
milestone50.0a1
Bug 1277155 - Part 1: Remove snprintf() polyfills for VS2013 in Sprintf.h and #defines. r=froydnj r=mhowell
b2g/app/nsBrowserApp.cpp
browser/app/nsBrowserApp.cpp
dom/media/android/AndroidMediaResourceServer.cpp
js/src/shell/OSObject.cpp
media/webrtc/signaling/src/sdp/sipcc/cpr_strings.h
mfbt/Snprintf.h
mozglue/misc/StackWalk.cpp
toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp
toolkit/components/ctypes/tests/jsctypes-test.cpp
toolkit/mozapps/update/common/updatedefines.h
tools/profiler/core/ProfileEntry.cpp
tools/profiler/public/GeckoProfilerImpl.h
xpcom/glue/nsStringAPI.cpp
xpcom/glue/standalone/nsXPCOMGlue.cpp
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -21,19 +21,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsIFile.h"
 #include "nsStringGlue.h"
 
 #ifdef XP_WIN
 // we want a wmain entry point
 #include "nsWindowsWMain.cpp"
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-#define snprintf _snprintf
-#endif
 #define strcasecmp _stricmp
 #endif
 
 #ifdef MOZ_WIDGET_GONK
 #include "BootAnimation.h"
 #endif
 
 #include "BinaryPath.h"
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -31,19 +31,16 @@
 
 #ifdef XP_WIN
 #ifdef MOZ_ASAN
 // ASAN requires firefox.exe to be built with -MD, and it's OK if we don't
 // support Windows XP SP2 in ASAN builds.
 #define XRE_DONT_SUPPORT_XPSP2
 #endif
 #define XRE_WANT_ENVIRON
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-#define snprintf _snprintf
-#endif
 #define strcasecmp _stricmp
 #ifdef MOZ_SANDBOX
 #include "mozilla/sandboxing/SandboxInitialization.h"
 #endif
 #endif
 #include "BinaryPath.h"
 
 #include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
--- a/dom/media/android/AndroidMediaResourceServer.cpp
+++ b/dom/media/android/AndroidMediaResourceServer.cpp
@@ -16,19 +16,16 @@
 #include "nsReadLine.h"
 #include "nsNetCID.h"
 #include "VideoUtils.h"
 #include "MediaResource.h"
 #include "AndroidMediaResourceServer.h"
 
 #if defined(_MSC_VER)
 #define strtoll _strtoi64
-#if _MSC_VER < 1900
-#define snprintf _snprintf_s
-#endif
 #endif
 
 using namespace mozilla;
 
 /*
   ReadCRLF is a variant of NS_ReadLine from nsReadLine.h that deals
   with the carriage return/line feed requirements of HTTP requests.
 */
--- a/js/src/shell/OSObject.cpp
+++ b/js/src/shell/OSObject.cpp
@@ -718,22 +718,17 @@ ReportSysError(JSContext* cx, const char
 
     size_t nbytes = strlen(prefix) + strlen(errstr) + 3;
     char* final = (char*) js_malloc(nbytes);
     if (!final) {
         JS_ReportOutOfMemory(cx);
         return;
     }
 
-#ifdef XP_WIN
-    _snprintf(final, nbytes, "%s: %s", prefix, errstr);
-#else
     snprintf(final, nbytes, "%s: %s", prefix, errstr);
-#endif
-
     JS_ReportError(cx, final);
     js_free(final);
 }
 
 static bool
 os_system(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
--- a/media/webrtc/signaling/src/sdp/sipcc/cpr_strings.h
+++ b/media/webrtc/signaling/src/sdp/sipcc/cpr_strings.h
@@ -2,25 +2,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _CPR_STRINGS_H_
 #define _CPR_STRINGS_H_
 
 #include "cpr_types.h"
 
-
 #include <string.h>
 
 #if defined(_MSC_VER)
 #define cpr_strcasecmp _stricmp
 #define cpr_strncasecmp _strnicmp
-#if _MSC_VER < 1900
-#define snprintf _snprintf
-#endif
 #else // _MSC_VER
 
 #define cpr_strcasecmp  strcasecmp
 #define cpr_strncasecmp strncasecmp
 
 #endif // _MSC_VER
 
 #endif
--- a/mfbt/Snprintf.h
+++ b/mfbt/Snprintf.h
@@ -5,37 +5,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Polyfills snprintf() on platforms that don't provide it, and provides
  * related utilities. */
 
 #ifndef mozilla_Snprintf_h_
 #define mozilla_Snprintf_h_
 
-#include <stddef.h>
 #include <stdio.h>
 #include <stdarg.h>
 
-// Older MSVC versions do not provide snprintf(), but they do provide
-// vsnprintf(), which has the same semantics except that if the number of
-// characters written equals the buffer size, it does not write a null
-// terminator, so we wrap it to do so.
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#include "mozilla/Attributes.h"
-MOZ_ALWAYS_INLINE int snprintf(char* buffer, size_t n, const char* format, ...)
-{
-  va_list args;
-  va_start(args, format);
-  int result = vsnprintf(buffer, n, format, args);
-  va_end(args);
-  buffer[n - 1] = '\0';
-  return result;
-}
-#endif
-
 // In addition, in C++ code, on all platforms, provide an snprintf_literal()
 // function which uses template argument deduction to deduce the size of the
 // buffer, avoiding the need for the user to pass it in explicitly.
 #ifdef __cplusplus
 template <size_t N>
 int snprintf_literal(char (&buffer)[N], const char* format, ...)
 {
   va_list args;
--- a/mozglue/misc/StackWalk.cpp
+++ b/mozglue/misc/StackWalk.cpp
@@ -8,20 +8,16 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/StackWalk.h"
 
 #include <string.h>
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#endif
-
 using namespace mozilla;
 
 // The presence of this address is the stack must stop the stack walk. If
 // there is no such address, the structure will be {nullptr, true}.
 struct CriticalAddress
 {
   void* mAddr;
   bool mInit;
--- a/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp
+++ b/toolkit/components/ctypes/tests/jsctypes-test-finalizer.cpp
@@ -1,17 +1,13 @@
 #include "errno.h"
 
 #include "jsctypes-test.h"
 #include "jsctypes-test-finalizer.h"
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#endif // defined(XP_WIN)
-
 /**
  * Shared infrastructure
  */
 
 
 /**
  * An array of integers representing resources.
  * - 0: unacquired
@@ -320,9 +316,8 @@ test_finalizer_rel_size_t_set_errno(size
   errno = 10;
 }
 
 void
 reset_errno()
 {
   errno = 0;
 }
-
--- a/toolkit/components/ctypes/tests/jsctypes-test.cpp
+++ b/toolkit/components/ctypes/tests/jsctypes-test.cpp
@@ -4,20 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsctypes-test.h"
 #include <math.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include "typedefs.h"
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#endif
-
 template <typename T> struct ValueTraits {
   static T literal() { return static_cast<T>(109.25); }
   static T sum(T a, T b) { return a + b; }
   static T sum_many(
     T a, T b, T c, T d, T e, T f, T g, T h, T i,
     T j, T k, T l, T m, T n, T o, T p, T q, T r)
   {
     return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r;
--- a/toolkit/mozapps/update/common/updatedefines.h
+++ b/toolkit/mozapps/update/common/updatedefines.h
@@ -49,35 +49,16 @@
 # endif
 # define DELETE_DIR L"tobedeleted"
 # define CALLBACK_BACKUP_EXT L".moz-callback"
 
 # define LOG_S "%S"
 # define NS_T(str) L ## str
 # define NS_SLASH NS_T('\\')
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-// On Windows, _snprintf and _snwprintf don't guarantee null termination. These
-// macros always leave room in the buffer for null termination and set the end
-// of the buffer to null in case the string is larger than the buffer. Having
-// multiple nulls in a string is fine and this approach is simpler (possibly
-// faster) than calculating the string length to place the null terminator and
-// truncates the string as _snprintf and _snwprintf do on other platforms.
-static inline int mysnprintf(char* dest, size_t count, const char* fmt, ...)
-{
-  size_t _count = count - 1;
-  va_list varargs;
-  va_start(varargs, fmt);
-  int result = _vsnprintf(dest, count - 1, fmt, varargs);
-  va_end(varargs);
-  dest[_count] = '\0';
-  return result;
-}
-#define snprintf mysnprintf
-#endif
 static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
 {
   size_t _count = count - 1;
   va_list varargs;
   va_start(varargs, fmt);
   int result = _vsnwprintf(dest, count - 1, fmt, varargs);
   va_end(varargs);
   dest[_count] = L'\0';
--- a/tools/profiler/core/ProfileEntry.cpp
+++ b/tools/profiler/core/ProfileEntry.cpp
@@ -15,20 +15,16 @@
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "js/TrackedOptimizationInfo.h"
 #endif
 
 // Self
 #include "ProfileEntry.h"
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
- #define snprintf _snprintf
-#endif
-
 using mozilla::MakeUnique;
 using mozilla::UniquePtr;
 using mozilla::Maybe;
 using mozilla::Some;
 using mozilla::Nothing;
 using mozilla::JSONWriter;
 
 
--- a/tools/profiler/public/GeckoProfilerImpl.h
+++ b/tools/profiler/public/GeckoProfilerImpl.h
@@ -439,23 +439,19 @@ public:
   {
     if (profiler_is_active() && !profiler_in_privacy_mode()) {
       va_list args;
       va_start(args, aFormat);
       char buff[SAMPLER_MAX_STRING];
 
       // We have to use seperate printf's because we're using
       // the vargs.
-#if _MSC_VER
-      _vsnprintf(buff, SAMPLER_MAX_STRING, aFormat, args);
-      _snprintf(mDest, SAMPLER_MAX_STRING, "%s %s", aInfo, buff);
-#else
       ::vsnprintf(buff, SAMPLER_MAX_STRING, aFormat, args);
       ::snprintf(mDest, SAMPLER_MAX_STRING, "%s %s", aInfo, buff);
-#endif
+
       mHandle = mozilla_sampler_call_enter(mDest, aCategory, this, true, line);
       va_end(args);
     } else {
       mHandle = mozilla_sampler_call_enter(aInfo, aCategory, this, false, line);
     }
   }
   ~SamplerStackFramePrintfRAII() {
     mozilla_sampler_call_exit(mHandle);
--- a/xpcom/glue/nsStringAPI.cpp
+++ b/xpcom/glue/nsStringAPI.cpp
@@ -8,20 +8,16 @@
 #include "nsCRTGlue.h"
 #include "prprf.h"
 #include "nsStringAPI.h"
 #include "nsXPCOMStrings.h"
 #include "nsDebug.h"
 
 #include <stdio.h>
 
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#endif
-
 // nsAString
 
 uint32_t
 nsAString::BeginReading(const char_type** aBegin, const char_type** aEnd) const
 {
   uint32_t len = NS_StringGetData(*this, aBegin);
   if (aEnd) {
     *aEnd = *aBegin + len;
@@ -1303,10 +1299,8 @@ ParseString(const nsACString& aSource, c
     start = ++delimiter;
     if (start == end) {
       break;
     }
   }
 
   return true;
 }
-
-#undef snprintf
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -35,19 +35,16 @@ static bool do_preload = false;
 #define LEADING_UNDERSCORE "_"
 #else
 #define LEADING_UNDERSCORE
 #endif
 
 #if defined(XP_WIN)
 #include <windows.h>
 #include <mbstring.h>
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#endif
 
 typedef HINSTANCE LibHandleType;
 
 static LibHandleType
 GetLibHandle(pathstr_t aDependentLib)
 {
   LibHandleType libHandle =
     LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);