Bug 1060419 - make WebGLContextUtils.cpp use VsprintfLiteral, r=froydnj
authorTom Tromey <tom@tromey.com>
Fri, 09 Dec 2016 13:48:22 -1000
changeset 343546 86fcf8b658e4708128463bb9572ccdd0cf490bb9
parent 343545 fee2788f109a4e898ddeaa74d63f5a877676afa4
child 343547 d89766e9ee6006ab37e97ef14d26be12e01ac0cc
push id31381
push userkwierso@gmail.com
push dateFri, 17 Feb 2017 20:45:51 +0000
treeherdermozilla-central@f302def88fe5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1060419
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1060419 - make WebGLContextUtils.cpp use VsprintfLiteral, r=froydnj MozReview-Commit-ID: JhwopeIpUMo
dom/canvas/TexUnpackBlob.cpp
dom/canvas/WebGL2ContextMRTs.cpp
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextState.cpp
dom/canvas/WebGLContextUtils.cpp
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLQuery.cpp
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLTextureUpload.cpp
dom/canvas/WebGLUniformLocation.cpp
--- a/dom/canvas/TexUnpackBlob.cpp
+++ b/dom/canvas/TexUnpackBlob.cpp
@@ -239,17 +239,17 @@ ValidateUnpackBytes(WebGLContext* webgl,
         return true;
 
     const auto bytesPerPixel = webgl::BytesPerPixel(pi);
     const auto bytesPerRow = CheckedUint32(blob->mRowLength) * bytesPerPixel;
     const auto rowStride = RoundUpToMultipleOf(bytesPerRow, blob->mAlignment);
 
     const auto fullRows = availByteCount / rowStride;
     if (!fullRows.isValid()) {
-        webgl->ErrorOutOfMemory("%s: Unacceptable upload size calculated.");
+        webgl->ErrorOutOfMemory("%s: Unacceptable upload size calculated.", funcName);
         return false;
     }
 
     const auto bodyBytes = fullRows.value() * rowStride.value();
     const auto tailPixels = (availByteCount - bodyBytes) / bytesPerPixel;
 
     return ValidateUnpackPixels(webgl, funcName, fullRows.value(), tailPixels, blob);
 }
--- a/dom/canvas/WebGL2ContextMRTs.cpp
+++ b/dom/canvas/WebGL2ContextMRTs.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "WebGL2Context.h"
 
 #include "GLContext.h"
 #include "WebGLFramebuffer.h"
+#include "mozilla/SizePrintfMacros.h"
 
 namespace mozilla {
 
 bool
 WebGL2Context::ValidateClearBuffer(const char* funcName, GLenum buffer, GLint drawBuffer,
                                    size_t availElemCount, GLuint elemOffset,
                                    GLenum funcType)
 {
@@ -50,17 +51,17 @@ WebGL2Context::ValidateClearBuffer(const
     if (drawBuffer < 0 || drawBuffer > maxDrawBuffer) {
         ErrorInvalidValue("%s: Invalid drawbuffer %d. This buffer only supports"
                           " `drawbuffer` values between 0 and %u.",
                           funcName, drawBuffer, maxDrawBuffer);
         return false;
     }
 
     if (availElemCount < requiredElements) {
-        ErrorInvalidValue("%s: Not enough elements. Require %u. Given %u.",
+        ErrorInvalidValue("%s: Not enough elements. Require %" PRIuSIZE ". Given %" PRIuSIZE ".",
                           funcName, requiredElements, availElemCount);
         return false;
     }
 
     ////
 
     MakeContextCurrent();
 
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -27,16 +27,17 @@
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/WebGLContextEvent.h"
 #include "mozilla/EnumeratedArrayCycleCollection.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ProcessPriorityManager.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Services.h"
+#include "mozilla/SizePrintfMacros.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsError.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIConsoleService.h"
 #include "nsIDOMEvent.h"
 #include "nsIGfxInfo.h"
@@ -749,17 +750,17 @@ WebGLContext::CreateAndInitGL(bool force
         FailureReason reason;
         if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
             reason.info = "Refused to create native OpenGL context because of blacklist"
                           " entry: ";
             reason.info.Append(reason.key);
 
             out_failReasons->push_back(reason);
 
-            GenerateWarning(reason.info.BeginReading());
+            GenerateWarning("%s", reason.info.BeginReading());
             tryNativeGL = false;
         }
     }
 
     //////
 
     if (tryNativeGL) {
         if (useEGL)
@@ -1206,23 +1207,23 @@ WebGLContext::LoseOldestWebGLContextIfLi
             if (contexts[i]->mLastUseIndex < oldestIndexThisPrincipal) {
                 oldestIndexThisPrincipal = contexts[i]->mLastUseIndex;
                 oldestContextThisPrincipal = contexts[i];
             }
         }
     }
 
     if (numContextsThisPrincipal > kMaxWebGLContextsPerPrincipal) {
-        GenerateWarning("Exceeded %d live WebGL contexts for this principal, losing the "
+        GenerateWarning("Exceeded %" PRIuSIZE " live WebGL contexts for this principal, losing the "
                         "least recently used one.", kMaxWebGLContextsPerPrincipal);
         MOZ_ASSERT(oldestContextThisPrincipal); // if we reach this point, this can't be null
         const_cast<WebGLContext*>(oldestContextThisPrincipal)->LoseContext();
     } else if (numContexts > kMaxWebGLContexts) {
-        GenerateWarning("Exceeded %d live WebGL contexts, losing the least recently used one.",
-                        kMaxWebGLContexts);
+        GenerateWarning("Exceeded %" PRIuSIZE " live WebGL contexts, losing the least "
+                        "recently used one.", kMaxWebGLContexts);
         MOZ_ASSERT(oldestContext); // if we reach this point, this can't be null
         const_cast<WebGLContext*>(oldestContext)->LoseContext();
     }
 }
 
 UniquePtr<uint8_t[]>
 WebGLContext::GetImageBuffer(int32_t* out_format)
 {
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -395,27 +395,27 @@ public:
      */
     virtual void DidRefresh() override;
 
     NS_IMETHOD Redraw(const gfxRect&) override {
         return NS_ERROR_NOT_IMPLEMENTED;
     }
 
     void SynthesizeGLError(GLenum err);
-    void SynthesizeGLError(GLenum err, const char* fmt, ...);
+    void SynthesizeGLError(GLenum err, const char* fmt, ...) MOZ_FORMAT_PRINTF(3, 4);
 
-    void ErrorInvalidEnum(const char* fmt = 0, ...);
-    void ErrorInvalidOperation(const char* fmt = 0, ...);
-    void ErrorInvalidValue(const char* fmt = 0, ...);
-    void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...);
+    void ErrorInvalidEnum(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
+    void ErrorInvalidOperation(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
+    void ErrorInvalidValue(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
+    void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
     void ErrorInvalidEnumInfo(const char* info, GLenum enumValue);
     void ErrorInvalidEnumInfo(const char* info, const char* funcName,
                               GLenum enumValue);
-    void ErrorOutOfMemory(const char* fmt = 0, ...);
-    void ErrorImplementationBug(const char* fmt = 0, ...);
+    void ErrorOutOfMemory(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
+    void ErrorImplementationBug(const char* fmt = 0, ...) MOZ_FORMAT_PRINTF(2, 3);
 
     void ErrorInvalidEnumArg(const char* funcName, const char* argName, GLenum val);
 
     const char* ErrorName(GLenum error);
 
     /**
      * Return displayable name for GLenum.
      * This version is like gl::GLenumToStr but with out the GL_ prefix to
@@ -2042,20 +2042,20 @@ protected:
     // these objects at high frequency. Having WebGLContext's hold one such object seems fine,
     // because WebGLContext objects only go away during GC, which shouldn't happen too frequently.
     // If in the future GC becomes much more frequent, we may have to revisit then (maybe use a timer).
     ForceDiscreteGPUHelperCGL mForceDiscreteGPUHelper;
 #endif
 
 public:
     // console logging helpers
-    void GenerateWarning(const char* fmt, ...);
+    void GenerateWarning(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
     void GenerateWarning(const char* fmt, va_list ap);
 
-    void GeneratePerfWarning(const char* fmt, ...) const;
+    void GeneratePerfWarning(const char* fmt, ...) const MOZ_FORMAT_PRINTF(2, 3);
 
 public:
     UniquePtr<webgl::FormatUsageAuthority> mFormatUsage;
 
     virtual UniquePtr<webgl::FormatUsageAuthority>
     CreateFormatUsage(gl::GLContext* gl) const = 0;
 
 
--- a/dom/canvas/WebGLContextState.cpp
+++ b/dom/canvas/WebGLContextState.cpp
@@ -642,17 +642,17 @@ WebGLContext::GetParameterIndexed(JSCont
     }
 
     MakeContextCurrent();
 
     switch (pname) {
         case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
         {
             if (index >= mGLMaxTransformFeedbackSeparateAttribs) {
-                ErrorInvalidValue("getParameterIndexed: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", index);
+                ErrorInvalidValue("getParameterIndexed: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS");
                 retval.setNull();
                 return;
             }
             retval.setNull(); // See bug 903594
             return;
         }
 
         default:
--- a/dom/canvas/WebGLContextUtils.cpp
+++ b/dom/canvas/WebGLContextUtils.cpp
@@ -5,23 +5,23 @@
 
 #include "WebGLContextUtils.h"
 #include "WebGLContext.h"
 
 #include "GLContext.h"
 #include "jsapi.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/Sprintf.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIVariant.h"
 #include "nsPrintfCString.h"
 #include "nsServiceManagerUtils.h"
-#include "prprf.h"
 #include <stdarg.h>
 #include "WebGLBuffer.h"
 #include "WebGLExtensions.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 
@@ -71,17 +71,17 @@ void
 WebGLContext::GenerateWarning(const char* fmt, va_list ap)
 {
     if (!ShouldGenerateWarnings())
         return;
 
     mAlreadyGeneratedWarnings++;
 
     char buf[1024];
-    PR_vsnprintf(buf, 1024, fmt, ap);
+    VsprintfLiteral(buf, fmt, ap);
 
     // no need to print to stderr, as JS_ReportWarning takes care of this for us.
 
     if (!mCanvasElement) {
         return;
     }
 
     dom::AutoJSAPI api;
@@ -124,17 +124,17 @@ WebGLContext::GeneratePerfWarning(const 
     JSContext* cx = api.cx();
 
     ////
 
     va_list ap;
     va_start(ap, fmt);
 
     char buf[1024];
-    PR_vsnprintf(buf, 1024, fmt, ap);
+    VsprintfLiteral(buf, fmt, ap);
 
     va_end(ap);
 
     ////
 
     JS_ReportWarningASCII(cx, "WebGL perf warning: %s", buf);
     mNumPerfWarnings++;
 
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -5,16 +5,17 @@
 
 #include "WebGLProgram.h"
 
 #include "GLContext.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "mozilla/RefPtr.h"
+#include "mozilla/SizePrintfMacros.h"
 #include "nsPrintfCString.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLContext.h"
 #include "WebGLShader.h"
 #include "WebGLTransformFeedback.h"
 #include "WebGLUniformLocation.h"
 #include "WebGLValidateStrings.h"
 
@@ -594,17 +595,17 @@ WebGLProgram::GetActiveAttrib(GLuint ind
     if (!mMostRecentLinkInfo) {
         RefPtr<WebGLActiveInfo> ret = WebGLActiveInfo::CreateInvalid(mContext);
         return ret.forget();
     }
 
     const auto& attribs = mMostRecentLinkInfo->attribs;
 
     if (index >= attribs.size()) {
-        mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
+        mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%" PRIuSIZE ").",
                                     index, "ACTIVE_ATTRIBS", attribs.size());
         return nullptr;
     }
 
     RefPtr<WebGLActiveInfo> ret = attribs[index].mActiveInfo;
     return ret.forget();
 }
 
@@ -615,17 +616,17 @@ WebGLProgram::GetActiveUniform(GLuint in
         // According to the spec, this can return null.
         RefPtr<WebGLActiveInfo> ret = WebGLActiveInfo::CreateInvalid(mContext);
         return ret.forget();
     }
 
     const auto& uniforms = mMostRecentLinkInfo->uniforms;
 
     if (index >= uniforms.size()) {
-        mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
+        mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%" PRIuSIZE ").",
                                     index, "ACTIVE_UNIFORMS", uniforms.size());
         return nullptr;
     }
 
     RefPtr<WebGLActiveInfo> ret = uniforms[index]->mActiveInfo;
     return ret.forget();
 }
 
--- a/dom/canvas/WebGLQuery.cpp
+++ b/dom/canvas/WebGLQuery.cpp
@@ -230,18 +230,17 @@ WebGLQuery::DeleteQuery()
 
     RequestDelete();
 }
 
 void
 WebGLQuery::QueryCounter(const char* funcName, GLenum target)
 {
     if (target != LOCAL_GL_TIMESTAMP_EXT) {
-        mContext->ErrorInvalidEnum("%s: `target` must be TIMESTAMP_EXT.", funcName,
-                                   target);
+        mContext->ErrorInvalidEnum("%s: `target` must be TIMESTAMP_EXT.", funcName);
         return;
     }
 
     if (mTarget && target != mTarget) {
         mContext->ErrorInvalidOperation("%s: Queries cannot change targets.", funcName);
         return;
     }
 
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLShader.h"
 
 #include "angle/ShaderLang.h"
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/SizePrintfMacros.h"
 #include "nsPrintfCString.h"
 #include "nsString.h"
 #include "prenv.h"
 #include "WebGLContext.h"
 #include "WebGLObjectModel.h"
 #include "WebGLShaderValidator.h"
 #include "WebGLValidateStrings.h"
 
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -12,16 +12,17 @@
 #include "GLBlitHelper.h"
 #include "GLContext.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/ImageBitmap.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Scoped.h"
+#include "mozilla/SizePrintfMacros.h"
 #include "mozilla/Unused.h"
 #include "ScopedGLHelpers.h"
 #include "TexUnpackBlob.h"
 #include "WebGLBuffer.h"
 #include "WebGLContext.h"
 #include "WebGLContextUtils.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLTexelConversions.h"
@@ -690,17 +691,17 @@ ValidateCompressedTexUnpack(WebGLContext
     if (!bytesNeeded.isValid()) {
         webgl->ErrorOutOfMemory("%s: Overflow while computing the needed buffer size.",
                                 funcName);
         return false;
     }
 
     if (dataSize != bytesNeeded.value()) {
         webgl->ErrorInvalidValue("%s: Provided buffer's size must match expected size."
-                                 " (needs %u, has %u)",
+                                 " (needs %u, has %" PRIuSIZE ")",
                                  funcName, bytesNeeded.value(), dataSize);
         return false;
     }
 
     return true;
 }
 
 static bool
@@ -1389,17 +1390,17 @@ WebGLTexture::TexSubImage(const char* fu
 
     if (glError == LOCAL_GL_OUT_OF_MEMORY) {
         mContext->ErrorOutOfMemory("%s: Driver ran out of memory during upload.",
                                    funcName);
         return;
     }
 
     if (glError) {
-        mContext->ErrorInvalidOperation("%s: Unexpected error during upload: 0x04x",
+        mContext->ErrorInvalidOperation("%s: Unexpected error during upload: 0x%04x",
                                         funcName, glError);
         MOZ_ASSERT(false, "Unexpected GL error.");
         return;
     }
 
     ////////////////////////////////////
     // Update our specification data?
 
--- a/dom/canvas/WebGLUniformLocation.cpp
+++ b/dom/canvas/WebGLUniformLocation.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "WebGLUniformLocation.h"
 
 #include "GLContext.h"
+#include "mozilla/SizePrintfMacros.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLContext.h"
 #include "WebGLProgram.h"
 
 namespace mozilla {
 
@@ -147,34 +148,34 @@ WebGLUniformLocation::ValidateArrayLengt
                                           const char* funcName) const
 {
     MOZ_ASSERT(mLinkInfo);
 
     if (setterArraySize == 0 ||
         setterArraySize % setterElemSize)
     {
         mContext->ErrorInvalidValue("%s: Expected an array of length a multiple of %d,"
-                                    " got an array of length %d.",
+                                    " got an array of length %" PRIuSIZE ".",
                                     funcName, setterElemSize, setterArraySize);
         return false;
     }
 
     /* GLES 2.0.25, Section 2.10, p38
      *   When loading `N` elements starting at an arbitrary position `k` in a uniform
      *   declared as an array, elements `k` through `k + N - 1` in the array will be
      *   replaced with the new values. Values for any array element that exceeds the
      *   highest array element index used, as reported by `GetActiveUniform`, will be
      *   ignored by GL.
      */
     if (!mInfo->mActiveInfo->mIsArray &&
         setterArraySize != setterElemSize)
     {
         mContext->ErrorInvalidOperation("%s: Expected an array of length exactly %d"
                                         " (since this uniform is not an array uniform),"
-                                        " got an array of length %d.",
+                                        " got an array of length %" PRIuSIZE ".",
                                         funcName, setterElemSize, setterArraySize);
         return false;
     }
 
     return true;
 }
 
 JS::Value