From 53648ab14e2f6a3cf07bd36b0964db8a0664b46a Mon Sep 17 00:00:00 2001 From: "djsollen@google.com" Date: Wed, 3 Apr 2013 12:34:16 +0000 Subject: Fix build error when building Android in Release mode with -O2. This fixes the folowing error... ../../../src/pdf/SkPDFShader.cpp: In function 'void gradientFunctionCode(const SkShader::GradientInfo&, SkString*)': ../../../src/pdf/SkPDFShader.cpp:69:19: error: array subscript is above array bounds [-Werror=array-bounds] Review URL: https://codereview.chromium.org/13471011 git-svn-id: http://skia.googlecode.com/svn/trunk@8506 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/pdf/SkPDFShader.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index b3e57cb951..b52111e25d 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -43,29 +43,29 @@ static void unitToPointsMatrix(const SkPoint pts[2], SkMatrix* matrix) { /* Assumes t + startOffset is on the stack and does a linear interpolation on t between startOffset and endOffset from prevColor to curColor (for each color - component), leaving the result in component order on the stack. + component), leaving the result in component order on the stack. It assumes + there are always 3 components per color. @param range endOffset - startOffset @param curColor[components] The current color components. @param prevColor[components] The previous color components. @param result The result ps function. */ static void interpolateColorCode(SkScalar range, SkScalar* curColor, - SkScalar* prevColor, int components, - SkString* result) { + SkScalar* prevColor, SkString* result) { + static const int kColorComponents = 3; + // Figure out how to scale each color component. - SkAutoSTMalloc<4, SkScalar> multiplierAlloc(components); - SkScalar *multiplier = multiplierAlloc.get(); - for (int i = 0; i < components; i++) { + SkScalar multiplier[kColorComponents]; + for (int i = 0; i < kColorComponents; i++) { multiplier[i] = SkScalarDiv(curColor[i] - prevColor[i], range); } // Calculate when we no longer need to keep a copy of the input parameter t. // If the last component to use t is i, then dupInput[0..i - 1] = true // and dupInput[i .. components] = false. - SkAutoSTMalloc<4, bool> dupInputAlloc(components); - bool *dupInput = dupInputAlloc.get(); - dupInput[components - 1] = false; - for (int i = components - 2; i >= 0; i--) { + bool dupInput[kColorComponents]; + dupInput[kColorComponents - 1] = false; + for (int i = kColorComponents - 2; i >= 0; i--) { dupInput[i] = dupInput[i + 1] || multiplier[i + 1] != 0; } @@ -73,7 +73,7 @@ static void interpolateColorCode(SkScalar range, SkScalar* curColor, result->append("pop "); } - for (int i = 0; i < components; i++) { + for (int i = 0; i < kColorComponents; i++) { // If the next components needs t and this component will consume a // copy, make another copy. if (dupInput[i] && multiplier[i] != 0) { @@ -159,8 +159,7 @@ static void gradientFunctionCode(const SkShader::GradientInfo& info, } interpolateColorCode(info.fColorOffsets[i] - info.fColorOffsets[i - 1], - colorData[i], colorData[i - 1], kColorComponents, - result); + colorData[i], colorData[i - 1], result); result->append("}\n"); } -- cgit v1.2.3