From 47ca692c8150cb39abef5737e866b91e6a105b80 Mon Sep 17 00:00:00 2001 From: weili Date: Thu, 31 Mar 2016 15:08:27 -0700 Subject: Re-enable all the windows warnings except 4267 The code is changed or had been changed to no longer generate these warnings. It is safe to re-enabled these warnings. In this code change, we fixed some code which generates warnings 4018 (signed/unsigned mismatch) and 4146 (unary minus operator applied to unsigned type, result still unsigned). Warning 4333 (right shift by too large amount, data loss) and 4345 (an object of POD type constructed with an initializer of the form () will be default-initialized) are no longer generated. The same setting is applied and verified for GN build as well. BUG=pdfium:29 Review URL: https://codereview.chromium.org/1849443003 --- core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp | 4 ++-- core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h | 2 +- core/fxcrt/fx_basic_gcc.cpp | 5 ++++- core/fxcrt/fx_basic_gcc_unittest.cpp | 11 ++++++----- core/fxge/ge/fx_ge_fontmap.cpp | 4 +++- 5 files changed, 16 insertions(+), 10 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp index a4b85a34fa..15f98b26b9 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp @@ -716,10 +716,10 @@ FX_BOOL CPDF_DataAvail::CheckFirstPage(IPDF_DataAvail::DownloadHints* pHints) { FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, uint32_t size, IPDF_DataAvail::DownloadHints* pHints) { - if (offset > m_dwFileLen) + if (offset < 0 || offset > m_dwFileLen) return TRUE; - FX_SAFE_DWORD safeSize = pdfium::base::checked_cast(offset); + FX_SAFE_FILESIZE safeSize = offset; safeSize += size; safeSize += 512; if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h index 26b6a8d3df..04fe6f4fec 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h @@ -83,7 +83,7 @@ class CPDF_SyntaxParser { FX_FILESIZE m_Pos; int m_MetadataObjnum; IFX_FileRead* m_pFileAccess; - uint32_t m_HeaderOffset; + FX_FILESIZE m_HeaderOffset; FX_FILESIZE m_FileLen; uint8_t* m_pFileBuf; uint32_t m_BufSize; diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp index 1b2f01ec89..c3afe1115b 100644 --- a/core/fxcrt/fx_basic_gcc.cpp +++ b/core/fxcrt/fx_basic_gcc.cpp @@ -39,7 +39,10 @@ IntType FXSYS_StrToInt(const CharType* str) { num = num * 10 + val; str++; } - return neg ? -num : num; + // When it is a negative value, -num should be returned. Since num may be of + // unsigned type, use ~num + 1 to avoid the warning of applying unary minus + // operator to unsigned type. + return neg ? ~num + 1 : num; } template diff --git a/core/fxcrt/fx_basic_gcc_unittest.cpp b/core/fxcrt/fx_basic_gcc_unittest.cpp index c6913cfd82..73e7446de0 100644 --- a/core/fxcrt/fx_basic_gcc_unittest.cpp +++ b/core/fxcrt/fx_basic_gcc_unittest.cpp @@ -16,15 +16,16 @@ TEST(fxcrt, FXSYS_atoi) { EXPECT_EQ(2345, FXSYS_atoi("+2345")); // The max value. EXPECT_EQ(2147483647, FXSYS_atoi("2147483647")); - // The min value. - EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483648")); + // The min value. Written in -1 format to avoid "unary minus operator applied + // to unsigned type" warning. + EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483648")); // With invalid char. EXPECT_EQ(9, FXSYS_atoi("9x9")); // Out of range values. EXPECT_EQ(2147483647, FXSYS_atoi("2147483623423412348")); EXPECT_EQ(2147483647, FXSYS_atoi("2147483648")); - EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483650")); + EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483650")); } TEST(fxcrt, FXSYS_atoi64) { @@ -58,13 +59,13 @@ TEST(fxcrt, FXSYS_wtoi) { // The max value. EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647")); // The min value. - EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483648")); + EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483648")); EXPECT_EQ(9, FXSYS_wtoi64(L"9x9")); // Out of range values. EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483623423412348")); EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483648")); - EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483652")); + EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483652")); } TEST(fxcrt, FXSYS_wtoi64) { diff --git a/core/fxge/ge/fx_ge_fontmap.cpp b/core/fxge/ge/fx_ge_fontmap.cpp index c6a6c5c003..c6b208c624 100644 --- a/core/fxge/ge/fx_ge_fontmap.cpp +++ b/core/fxge/ge/fx_ge_fontmap.cpp @@ -681,15 +681,17 @@ void CFX_FontMapper::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) { } m_pFontInfo = pFontInfo; } + static CFX_ByteString GetStringFromTable(const uint8_t* string_ptr, uint32_t string_ptr_length, uint16_t offset, uint16_t length) { - if (string_ptr_length < offset + length) { + if (string_ptr_length < static_cast(offset + length)) { return CFX_ByteString(); } return CFX_ByteStringC(string_ptr + offset, length); } + CFX_ByteString GetNameFromTT(const uint8_t* name_table, uint32_t name_table_size, uint32_t name_id) { -- cgit v1.2.3