summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-06-03 11:22:16 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-03 11:22:16 -0700
commit12367cb5e83e771cd67948c810fdd5f63d61af87 (patch)
tree47daac780e5c028ba531830b514c0c60102f1368
parent79d798da0d4b5f9f1fc27917102bdd7bcfbe863e (diff)
downloadpdfium-12367cb5e83e771cd67948c810fdd5f63d61af87.tar.xz
Fix some code which causes warnings when compiled by /analyze tool
The code may not cause error conditions, but can be improved. These warnings include uninitialized variables, signed/unsigned mismatch, redundant condition, and using bool in arithmetic operations. Also remove a chunk of unused code. BUG=chromium:613623, chromium:427616 Review-Url: https://codereview.chromium.org/2036203004
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp2
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp4
-rw-r--r--core/fxcodec/codec/fx_codec.cpp102
-rw-r--r--core/fxcodec/codec/fx_codec_png.cpp2
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp2
-rw-r--r--fpdfsdk/fpdf_flatten.cpp3
-rw-r--r--fpdfsdk/fsdk_baseannot.cpp8
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp2
8 files changed, 12 insertions, 113 deletions
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
index 4fd26b9153..308c9f11c9 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
@@ -73,7 +73,7 @@ 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;
+ unsigned char* result = nullptr;
unsigned int result_size;
EXPECT_EQ(data.processed_size,
FlateDecode(data.input, data.input_size, result, result_size))
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
index 352e4ee15c..cd96c4a72a 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
@@ -29,7 +29,7 @@ TEST(fpdf_parser_decode, A85Decode) {
for (size_t i = 0; i < FX_ArraySize(test_data); ++i) {
pdfium::DecodeTestData* ptr = &test_data[i];
uint8_t* result = nullptr;
- uint32_t result_size;
+ uint32_t result_size = 0;
EXPECT_EQ(ptr->processed_size,
A85Decode(ptr->input, ptr->input_size, result, result_size))
<< "for case " << i;
@@ -64,7 +64,7 @@ TEST(fpdf_parser_decode, HexDecode) {
for (size_t i = 0; i < FX_ArraySize(test_data); ++i) {
pdfium::DecodeTestData* ptr = &test_data[i];
uint8_t* result = nullptr;
- uint32_t result_size;
+ uint32_t result_size = 0;
EXPECT_EQ(ptr->processed_size,
HexDecode(ptr->input, ptr->input_size, result, result_size))
<< "for case " << i;
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp
index f0f03ab0e9..997d61f25b 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/codec/fx_codec.cpp
@@ -84,108 +84,6 @@ FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf,
return FALSE;
}
-#define EXPONENT_DETECT(ptr) \
- for (;; ptr++) { \
- if (!std::isdigit(*ptr)) { \
- if (endptr) \
- *endptr = (char*)ptr; \
- break; \
- } else { \
- exp_ret *= 10; \
- exp_ret += FXSYS_toDecimalDigit(*ptr); \
- continue; \
- } \
- }
-
-extern "C" double FXstrtod(const char* nptr, char** endptr) {
- double ret = 0.0;
- const char* ptr = nptr;
- const char* exp_ptr = NULL;
- int e_number = 0, e_signal = 0, e_point = 0, is_negative = 0;
- int exp_ret = 0, exp_sig = 1, fra_ret = 0, fra_count = 0, fra_base = 1;
- if (!nptr) {
- return 0.0;
- }
- for (;; ptr++) {
- if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' '))
- continue;
-
- if (std::isdigit(*ptr)) {
- if (!e_number)
- e_number = 1;
-
- if (!e_point) {
- ret *= 10;
- ret += FXSYS_toDecimalDigit(*ptr);
- } else {
- fra_count++;
- fra_ret *= 10;
- fra_ret += FXSYS_toDecimalDigit(*ptr);
- }
- continue;
- }
- if (!e_point && *ptr == '.') {
- e_point = 1;
- continue;
- }
- if (!e_number && !e_point && !e_signal) {
- switch (*ptr) {
- case '-':
- is_negative = 1;
- case '+':
- e_signal = 1;
- continue;
- }
- }
- if (e_number && (*ptr == 'e' || *ptr == 'E')) {
- exp_ptr = ptr++;
- if (*ptr == '+' || *ptr == '-') {
- exp_sig = (*ptr++ == '+') ? 1 : -1;
- if (!std::isdigit(*ptr)) {
- if (endptr) {
- *endptr = (char*)exp_ptr;
- }
- break;
- }
- EXPONENT_DETECT(ptr);
- } else if (std::isdigit(*ptr)) {
- EXPONENT_DETECT(ptr);
- } else {
- if (endptr) {
- *endptr = (char*)exp_ptr;
- }
- break;
- }
- break;
- }
- if (ptr != nptr && !e_number) {
- if (endptr) {
- *endptr = (char*)nptr;
- }
- break;
- }
- if (endptr) {
- *endptr = (char*)ptr;
- }
- break;
- }
- while (fra_count--) {
- fra_base *= 10;
- }
- ret += (double)fra_ret / (double)fra_base;
- if (exp_sig == 1) {
- while (exp_ret--) {
- ret *= 10.0;
- }
- } else {
- while (exp_ret--) {
- ret /= 10.0;
- }
- }
- return is_negative ? -ret : ret;
-}
-#undef EXPONENT_DETECT
-
FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf,
uint32_t src_size,
uint8_t*& dest_buf,
diff --git a/core/fxcodec/codec/fx_codec_png.cpp b/core/fxcodec/codec/fx_codec_png.cpp
index 61d4cebdbb..f7b922973e 100644
--- a/core/fxcodec/codec/fx_codec_png.cpp
+++ b/core/fxcodec/codec/fx_codec_png.cpp
@@ -56,7 +56,7 @@ static void _png_load_bmp_attribute(png_structp png_ptr,
if (t) {
FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime));
FXSYS_snprintf((FX_CHAR*)pAttribute->m_strTime,
- sizeof(pAttribute->m_strTime), "%4d:%2d:%2d %2d:%2d:%2d",
+ sizeof(pAttribute->m_strTime), "%4u:%2u:%2u %2u:%2u:%2u",
t->year, t->month, t->day, t->hour, t->minute, t->second);
pAttribute->m_strTime[sizeof(pAttribute->m_strTime) - 1] = 0;
bTime = 1;
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index a0a411fbcf..25c9ff7649 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -631,7 +631,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
return JBIG2_ERROR_FATAL;
m_pStream->alignByte();
}
- if (m_bIsGlobal && kSymbolDictCacheMaxSize > 0) {
+ if (m_bIsGlobal) {
std::unique_ptr<CJBig2_SymbolDict> value =
pSegment->m_Result.sd->DeepCopy();
int size = pdfium::CollectionSize<int>(*m_pSymbolDictCache);
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 2d11bfee7b..27646255c8 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -156,7 +156,8 @@ FX_FLOAT GetMinMaxValue(CPDF_RectArray& array,
break;
}
default:
- break;
+ // Not reachable.
+ return 0.0f;
}
fRet = pArray[0];
if (type == MAX) {
diff --git a/fpdfsdk/fsdk_baseannot.cpp b/fpdfsdk/fsdk_baseannot.cpp
index e2ee6f7c73..1345f234b6 100644
--- a/fpdfsdk/fsdk_baseannot.cpp
+++ b/fpdfsdk/fsdk_baseannot.cpp
@@ -346,14 +346,14 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
CFX_ByteString str1;
- str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
+ str1.Format("%04d-%02u-%02u %02u:%02u:%02u ", dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second);
if (dt.tzHour < 0)
str1 += "-";
else
str1 += "+";
CFX_ByteString str2;
- str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
+ str2.Format("%02d:%02u", abs(dt.tzHour), dt.tzMinute);
return str1 + str2;
}
@@ -361,7 +361,7 @@ CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
CFX_ByteString dtStr;
char tempStr[32];
memset(tempStr, 0, sizeof(tempStr));
- FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
+ FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02u%02u%02u%02u%02u",
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
dtStr = CFX_ByteString(tempStr);
if (dt.tzHour < 0)
@@ -369,7 +369,7 @@ CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
else
dtStr += CFX_ByteString("+");
memset(tempStr, 0, sizeof(tempStr));
- FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour),
+ FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02u'", abs(dt.tzHour),
dt.tzMinute);
dtStr += CFX_ByteString(tempStr);
return dtStr;
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index ab02f02cfb..b01ee586e1 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -718,7 +718,7 @@ int _MonthFromTime(double t) {
int _DateFromTime(double t) {
int day = _DayWithinYear(t);
int year = _YearFromTime(t);
- bool leap = _isLeapYear(year);
+ int leap = _isLeapYear(year);
int month = _MonthFromTime(t);
switch (month) {
case 0: