From a9a4b04a98f9990e4e11b164b2eed37416768f21 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Wed, 27 Nov 2013 17:00:12 +0000 Subject: [PATCH] Fix Valgrind reports of test branching on uninitialized data. Fixes reports like: [07:10:01.235147] [ 71/188] (9) Serialization [07:10:01.235186] ==20052== Thread 3: [07:10:01.235223] ==20052== Conditional jump or move depends on uninitialised value(s) [07:10:01.235259] ==20052== at 0x546632: SkRRect::setRectRadii(SkRect const&, SkPoint const*) (SkRect.h:426) [07:10:01.735876] ==20052== by 0x546FB7: SkRRect::readFromMemory(void const*, unsigned long) (SkRRect.cpp:362) [07:10:01.735965] ==20052== by 0x47F87F: Tests(skiatest::Reporter*) (SerializationTest.cpp:20) [07:10:01.736007] ==20052== by 0x480367: skiatest::SerializationClass::onRun(skiatest::Reporter*) (SerializationTest.cpp:212) [07:10:01.736048] ==20052== by 0x4881DA: skiatest::Test::run() (Test.cpp:109) [07:10:01.736086] ==20052== by 0x482516: SkTestRunnable::run() (skia_test.cpp:155) [07:10:01.736122] ==20052== by 0x6236E5: SkThreadPool::Loop(void*) (SkThreadPool.cpp:97) [07:10:01.736158] ==20052== by 0x62DDB2: thread_start(void*) (SkThreadUtils_pthread.cpp:66) [07:10:01.736192] ==20052== by 0x4E39E99: start_thread (pthread_create.c:308) [07:10:01.736228] ==20052== by 0x6A5BCCC: clone (clone.S:112) [07:10:01.736262] ==20052== Uninitialised value was created by a stack allocation [07:10:01.736296] ==20052== at 0x47EC6A: Tests(skiatest::Reporter*) (SerializationTest.cpp:155) git-svn-id: http://skia.googlecode.com/svn/trunk@12419 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/SerializationTest.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index f49abe910..9e63249c6 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -173,37 +173,43 @@ static void Tests(skiatest::Reporter* reporter) { // Test rrect serialization { + // SkRRect does not initialize anything. + // An uninitialized SkRRect can be serialized, + // but will branch on uninitialized data when deserialized. SkRRect rrect; + SkRect rect = SkRect::MakeXYWH(1, 2, 20, 30); + SkVector corners[4] = { {1, 2}, {2, 3}, {3,4}, {4,5} }; + rrect.setRectRadii(rect, corners); TestAlignment(&rrect, reporter); } // Test readByteArray { - unsigned char data[kArraySize] = {0}; + unsigned char data[kArraySize] = { 1, 2, 3 }; TestArraySerialization(data, reporter); } // Test readColorArray { - SkColor data[kArraySize]; + SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }; TestArraySerialization(data, reporter); } // Test readIntArray { - int32_t data[kArraySize]; + int32_t data[kArraySize] = { 1, 2, 4, 8 }; TestArraySerialization(data, reporter); } // Test readPointArray { - SkPoint data[kArraySize]; + SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; TestArraySerialization(data, reporter); } // Test readScalarArray { - SkScalar data[kArraySize]; + SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; TestArraySerialization(data, reporter); } }