Bug 968425 - Remove the null-term char from the end of getShaderInfoLog strings. r=bjacob
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 19 Feb 2014 11:45:38 -0500
changeset 169890 bbe8c54029e2db314931b0fe524b2d69e2a0a787
parent 169889 dc46d95c478718d308667ffff72b11fe5bd64d5e
child 169891 679e69e79fe2f7fd80e2b4f3073c31a9db130a24
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbjacob
bugs968425
milestone30.0a1
Bug 968425 - Remove the null-term char from the end of getShaderInfoLog strings. r=bjacob
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -3219,26 +3219,30 @@ WebGLContext::CompileShader(WebGLShader 
 #endif
         }
 
 #ifdef WEBGL2_BYPASS_ANGLE
         if (!ShCompile(compiler, &angleShaderCode, 1, compileOptions)) {
 #else
         if (!ShCompile(compiler, &s, 1, compileOptions)) {
 #endif
-            size_t len = 0;
-            ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &len);
-
-            if (len) {
+            size_t lenWithNull = 0;
+            ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &lenWithNull);
+
+            if (!lenWithNull) {
+                // Error in ShGetInfo.
+                shader->SetTranslationFailure(NS_LITERAL_CSTRING("Internal error: failed to get shader info log"));
+            } else {
+                size_t len = lenWithNull - 1;
+
                 nsAutoCString info;
-                info.SetLength(len);
+                info.SetLength(len); // Allocates len+1, for the null-term.
                 ShGetInfoLog(compiler, info.BeginWriting());
+
                 shader->SetTranslationFailure(info);
-            } else {
-                shader->SetTranslationFailure(NS_LITERAL_CSTRING("Internal error: failed to get shader info log"));
             }
             ShDestruct(compiler);
             shader->SetCompileStatus(false);
             return;
         }
 
         size_t num_attributes = 0;
         ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTES, &num_attributes);