diff options
author | Lei Zhang <thestig@chromium.org> | 2018-09-11 07:58:38 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-11 07:58:38 +0000 |
commit | c2f404f993f13d303f9e47d2f97aff727becac7d (patch) | |
tree | 29d29f827c701da54334b894364ec5ea12dedc96 /core/fxcodec/codec | |
parent | 8365e76fe8a311eaf77c4b5d5c0b199de0238f07 (diff) | |
download | pdfium-c2f404f993f13d303f9e47d2f97aff727becac7d.tar.xz |
Make RunLengthDecode()'s buffer out parameter a unique_ptr.
Change-Id: I1dc99831a564e88035c317455411f1eba9aa41c4
Reviewed-on: https://pdfium-review.googlesource.com/41852
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r-- | core/fxcodec/codec/fx_codec_rle_unittest.cpp | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/core/fxcodec/codec/fx_codec_rle_unittest.cpp b/core/fxcodec/codec/fx_codec_rle_unittest.cpp index 62ea4e7a76..3ee0aa6368 100644 --- a/core/fxcodec/codec/fx_codec_rle_unittest.cpp +++ b/core/fxcodec/codec/fx_codec_rle_unittest.cpp @@ -5,6 +5,7 @@ #include <stdint.h> #include <limits> +#include <memory> #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fxcodec/codec/ccodec_basicmodule.h" @@ -63,40 +64,37 @@ TEST(fxcodec, RLETestNormalInputs) { // Case 1: EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_1, &dest_buf, &dest_size)); - uint8_t* decoded_buf = nullptr; + std::unique_ptr<uint8_t, FxFreeDeleter> decoded_buf; uint32_t decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_1), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_1[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); // Case 2: dest_buf = nullptr; dest_size = 0; EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_2, &dest_buf, &dest_size)); - decoded_buf = nullptr; + decoded_buf.reset(); decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_2), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_2[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); // Case 3: dest_buf = nullptr; dest_size = 0; EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_3, &dest_buf, &dest_size)); - decoded_buf = nullptr; + decoded_buf.reset(); decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_3), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_3[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); } // Check that runs longer than 128 are broken up properly, both matched and @@ -128,51 +126,47 @@ TEST(fxcodec, RLETestFullLengthInputs) { // Case 1: EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_1, &dest_buf, &dest_size)); - uint8_t* decoded_buf = nullptr; + std::unique_ptr<uint8_t, FxFreeDeleter> decoded_buf; uint32_t decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_1), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_1[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); // Case 2: dest_buf = nullptr; dest_size = 0; EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_2, &dest_buf, &dest_size)); - decoded_buf = nullptr; + decoded_buf.reset(); decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_2), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_2[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); // Case 3: dest_buf = nullptr; dest_size = 0; EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_3, &dest_buf, &dest_size)); - decoded_buf = nullptr; + decoded_buf.reset(); decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_3), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_3[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); // Case 4: dest_buf = nullptr; dest_size = 0; EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_4, &dest_buf, &dest_size)); - decoded_buf = nullptr; + decoded_buf.reset(); decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(sizeof(src_buf_4), decoded_size); for (uint32_t i = 0; i < decoded_size; i++) - EXPECT_EQ(src_buf_4[i], decoded_buf[i]) << " at " << i; + EXPECT_EQ(src_buf_4[i], decoded_buf.get()[i]) << " at " << i; FX_Free(dest_buf); - FX_Free(decoded_buf); } |