diff options
author | U. Artie Eoff <ullysses.a.eoff@intel.com> | 2016-09-07 12:22:44 -0700 |
---|---|---|
committer | Sean V Kelley <seanvk@posteo.de> | 2016-09-07 12:31:35 -0700 |
commit | 871626e6ee3cc6e76b7ebb51fd84ace469c77346 (patch) | |
tree | 625c2830187f7b3793a17aa79c6efb17c5888bc8 /test | |
parent | f287e43e8f6b0ab52e5f78bd748dfef72f4c461d (diff) |
test: fix jpeg decode invalid indexing
Use hsample and vsample factor in printComponentDataTo to
avoid invalid indexes into the data array.
This fixes a segfault in the jpeg fourcc tests that may be
triggered during 'make check'.
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/i965_jpeg_decode_test.cpp | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/test/i965_jpeg_decode_test.cpp b/test/i965_jpeg_decode_test.cpp index 6a17d1e..3a1c68f 100644 --- a/test/i965_jpeg_decode_test.cpp +++ b/test/i965_jpeg_decode_test.cpp @@ -133,43 +133,42 @@ protected: } } - TestPattern::SharedConst testPattern; - PictureData::SharedConst pd; -}; - -void printComponentDataTo(std::ostream& os, const uint8_t * const data, - unsigned w, unsigned h, unsigned pitch) -{ - os << " "; - for (unsigned i(0); i < w; ++i) - os << std::setw(4) << i << " "; - os << std::endl; - - const uint8_t *row = data; - for (unsigned i(0); i < h; ++i) { - os << std::dec << std::setfill(' ') << std::setw(3) << (i * w) << " "; - for (size_t j(0); j < w; ++j) { - os << "0x" << std::hex << std::setfill('0') << std::setw(2) - << (uint32_t)row[j] << ","; + void printComponentDataTo(std::ostream& os, const uint8_t * const data, + unsigned w, unsigned h, unsigned pitch, unsigned hsample = 1, + unsigned vsample = 1) + { + const uint8_t *row = data; + for (unsigned i(0); i < (h/vsample); ++i) { + for (size_t j(0); j < (w/hsample); ++j) { + os << "0x" << std::hex << std::setfill('0') << std::setw(2) + << (uint32_t)row[j] << ","; + } + os << std::endl; + row += pitch; } - os << std::endl; - row += pitch; + os << std::setw(0) << std::setfill(' ') << std::dec << std::endl; } - os << std::setw(0) << std::setfill(' ') << std::dec << std::endl; -} -void printImageOutputTo(std::ostream& os, const VAImage& image, - const uint8_t * const output) -{ - printComponentDataTo(os, output + image.offsets[0], image.width, - image.height, image.pitches[0]); // Y - - printComponentDataTo(os, output + image.offsets[1], image.width, - image.height, image.pitches[1]); // U + void printImageOutputTo(std::ostream& os, const VAImage& image, + const uint8_t * const output) + { + printComponentDataTo(os, output + image.offsets[0], image.width, + image.height, image.pitches[0]); // Y + + printComponentDataTo(os, output + image.offsets[1], image.width, + image.height, image.pitches[1], + pd->pparam.components[0].h_sampling_factor, + pd->pparam.components[0].v_sampling_factor); // U + + printComponentDataTo(os, output + image.offsets[2], image.width, + image.height, image.pitches[2], + pd->pparam.components[0].h_sampling_factor, + pd->pparam.components[0].v_sampling_factor); // V + } - printComponentDataTo(os, output + image.offsets[2], image.width, - image.height, image.pitches[2]); // V -} + TestPattern::SharedConst testPattern; + PictureData::SharedConst pd; +}; #define ASSERT_NO_FAILURE(statement) \ statement; \ |