summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-11-02 19:27:08 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-02 19:27:08 +0000
commita6adac83c6aadbacf2a338d2e55148f7d3417762 (patch)
tree2a2199d74d18545d2fffd7bad3c44478b6560dce /core/fpdfapi/parser
parent23efbbd8a1840d5dd746d94069741b0532b61b14 (diff)
downloadpdfium-a6adac83c6aadbacf2a338d2e55148f7d3417762.tar.xz
Remove some C-style const char* casts.
Change-Id: I4785dd277b9da072ee3c55e2aaeb688bbf02852e Reviewed-on: https://pdfium-review.googlesource.com/17391 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp12
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp7
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp30
3 files changed, 28 insertions, 21 deletions
diff --git a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
index a2f43386e7..e8d3b7142a 100644
--- a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
@@ -11,7 +11,7 @@
#include "testing/test_support.h"
TEST(SimpleParserTest, GetWord) {
- pdfium::StrFuncTestData test_data[] = {
+ static const pdfium::StrFuncTestData test_data[] = {
// Empty src string.
STR_IN_OUT_CASE("", ""),
// Content with whitespaces only.
@@ -51,15 +51,17 @@ TEST(SimpleParserTest, GetWord) {
const pdfium::StrFuncTestData& data = test_data[i];
CPDF_SimpleParser parser(data.input, data.input_size);
ByteStringView word = parser.GetWord();
- EXPECT_EQ(std::string(reinterpret_cast<const char*>(data.expected),
- data.expected_size),
- std::string(word.unterminated_c_str(), word.GetLength()))
+ EXPECT_EQ(data.expected_size, word.GetLength()) << " for case " << i;
+ if (data.expected_size != word.GetLength())
+ continue;
+ EXPECT_EQ(
+ 0, memcmp(data.expected, word.unterminated_c_str(), data.expected_size))
<< " for case " << i;
}
}
TEST(SimpleParserTest, FindTagParamFromStart) {
- struct FindTagTestStruct {
+ static const struct FindTagTestStruct {
const unsigned char* input;
unsigned int input_size;
const char* token;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index f0ea5ac5b0..ddf420b34a 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -337,9 +337,10 @@ void CPDF_SyntaxParser::ToNextWord() {
ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) {
const CPDF_ReadValidator::Session read_session(GetValidator().Get());
GetNextWordInternal(bIsNumber);
- return GetValidator()->has_read_problems()
- ? ByteString()
- : ByteString((const char*)m_WordBuffer, m_WordSize);
+ ByteString ret;
+ if (!GetValidator()->has_read_problems())
+ ret = ByteString(m_WordBuffer, m_WordSize);
+ return ret;
}
ByteString CPDF_SyntaxParser::PeekNextWord(bool* bIsNumber) {
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
index bf2fd6d10f..e95a4cc595 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
@@ -11,13 +11,13 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
-class FPDFParserDecodeEmbeddertest : public EmbedderTest {};
+using FPDFParserDecodeEmbeddertest = EmbedderTest;
// NOTE: python's zlib.compress() and zlib.decompress() may be useful for
// external validation of the FlateEncode/FlateDecode test cases.
TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) {
- pdfium::StrFuncTestData flate_encode_cases[] = {
+ static const pdfium::StrFuncTestData flate_encode_cases[] = {
STR_IN_OUT_CASE("", "\x78\x9c\x03\x00\x00\x00\x00\x01"),
STR_IN_OUT_CASE(" ", "\x78\x9c\x53\x00\x00\x00\x21\x00\x21"),
STR_IN_OUT_CASE("123", "\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97"),
@@ -37,18 +37,20 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) {
for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
const pdfium::StrFuncTestData& data = flate_encode_cases[i];
unsigned char* buf = nullptr;
- unsigned int buf_size;
+ uint32_t buf_size;
EXPECT_TRUE(FlateEncode(data.input, data.input_size, &buf, &buf_size));
ASSERT_TRUE(buf);
- EXPECT_EQ(std::string((const char*)data.expected, data.expected_size),
- std::string((const char*)buf, buf_size))
+ EXPECT_EQ(data.expected_size, buf_size) << " for case " << i;
+ if (data.expected_size != buf_size)
+ continue;
+ EXPECT_EQ(0, memcmp(data.expected, buf, data.expected_size))
<< " for case " << i;
FX_Free(buf);
}
}
TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) {
- pdfium::DecodeTestData flate_decode_cases[] = {
+ static const pdfium::DecodeTestData flate_decode_cases[] = {
STR_IN_OUT_CASE("", "", 0),
STR_IN_OUT_CASE("preposterous nonsense", "", 2),
STR_IN_OUT_CASE("\x78\x9c\x03\x00\x00\x00\x00\x01", "", 8),
@@ -71,16 +73,18 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) {
for (size_t i = 0; i < FX_ArraySize(flate_decode_cases); ++i) {
const pdfium::DecodeTestData& data = flate_decode_cases[i];
- unsigned char* result = nullptr;
- unsigned int result_size;
+ unsigned char* buf = nullptr;
+ uint32_t buf_size;
EXPECT_EQ(data.processed_size,
- FlateDecode(data.input, data.input_size, &result, &result_size))
+ FlateDecode(data.input, data.input_size, &buf, &buf_size))
<< " for case " << i;
- ASSERT_TRUE(result);
- EXPECT_EQ(std::string((const char*)data.expected, data.expected_size),
- std::string((const char*)result, result_size))
+ ASSERT_TRUE(buf);
+ EXPECT_EQ(data.expected_size, buf_size) << " for case " << i;
+ if (data.expected_size != buf_size)
+ continue;
+ EXPECT_EQ(0, memcmp(data.expected, buf, data.expected_size))
<< " for case " << i;
- FX_Free(result);
+ FX_Free(buf);
}
}