From ae195a4242a81899708eb58e109fd0d1a9cbbeeb Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 1 Jul 2015 14:08:08 -0700 Subject: Fix some clang warnings with -Wmissing-braces in pdfium. Clang warns if there are missing braces around a subobject initializer. The most common idiom that triggers this is: STRUCT s = {0}; if the first field of STRUCT is itself a struct. This can be more simply written as: STRUCT s = {}; which also prevents the warning from firing. Other instances of the warning have been fixed by adding braces where appropriate. R=brucedawson@chromium.org Review URL: https://codereview.chromium.org/1213523004. --- core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 2 +- core/src/fxcrt/fxcrt_windows.cpp | 8 ++++---- fpdfsdk/src/fpdf_flatten.cpp | 2 +- fpdfsdk/src/javascript/util.cpp | 8 ++++---- samples/pdfium_test.cc | 4 ++-- third_party/BUILD.gn | 8 ++++++++ third_party/third_party.gyp | 5 +++++ 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index ff1f6c4aa0..3d12ee9c82 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -154,7 +154,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() } void CPDF_StreamContentParser::ParsePathObject() { - FX_FLOAT params[6] = {0}; + FX_FLOAT params[6] = {}; int nParams = 0; int last_pos = m_pSyntax->GetPos(); while (1) { diff --git a/core/src/fxcrt/fxcrt_windows.cpp b/core/src/fxcrt/fxcrt_windows.cpp index 34d918b6fa..d4e3830cf2 100644 --- a/core/src/fxcrt/fxcrt_windows.cpp +++ b/core/src/fxcrt/fxcrt_windows.cpp @@ -98,7 +98,7 @@ FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const if (!m_hFile) { return 0; } - LARGE_INTEGER size = {0, 0}; + LARGE_INTEGER size = {}; if (!::GetFileSizeEx(m_hFile, &size)) { return 0; } @@ -109,8 +109,8 @@ FX_FILESIZE CFXCRT_FileAccess_Win64::GetPosition() const if (!m_hFile) { return (FX_FILESIZE) - 1; } - LARGE_INTEGER dist = {0, 0}; - LARGE_INTEGER newPos = {0, 0}; + LARGE_INTEGER dist = {}; + LARGE_INTEGER newPos = {}; if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_CURRENT)) { return (FX_FILESIZE) - 1; } @@ -123,7 +123,7 @@ FX_FILESIZE CFXCRT_FileAccess_Win64::SetPosition(FX_FILESIZE pos) } LARGE_INTEGER dist; dist.QuadPart = pos; - LARGE_INTEGER newPos = {0, 0}; + LARGE_INTEGER newPos = {}; if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN)) { return (FX_FILESIZE) - 1; } diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp index d3aa8c5ec1..988d7f46b5 100644 --- a/fpdfsdk/src/fpdf_flatten.cpp +++ b/fpdfsdk/src/fpdf_flatten.cpp @@ -410,7 +410,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag) { for (int iKey = 0; /*iKey < 100*/; iKey++) { - char sExtend[5] = {0}; + char sExtend[5] = {}; FXSYS_itoa(iKey, sExtend, 10); key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp index 22e1c6dd99..c4f03093a7 100644 --- a/fpdfsdk/src/javascript/util.cpp +++ b/fpdfsdk/src/javascript/util.cpp @@ -303,7 +303,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& iMin = jsDate.GetMinutes(); iSec = jsDate.GetSeconds(); - struct tm time = {0}; + struct tm time = {}; time.tm_year = iYear-1900; time.tm_mon = iMonth; time.tm_mday = iDay; @@ -360,7 +360,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& CFX_WideString strFormat; // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec); // CString strFormat = cppTm.Format(cFormat.c_str()); - wchar_t buf[64] = {0}; + wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; vRet = cFormat.c_str(); @@ -399,7 +399,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur iMin = jsDate.GetMinutes(); iSec = jsDate.GetSeconds(); - struct tm time = {0}; + struct tm time = {}; time.tm_year = iYear-1900; time.tm_mon = iMonth; time.tm_mday = iDay; @@ -454,7 +454,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur } CFX_WideString strFormat; - wchar_t buf[64] = {0}; + wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; cPurpose = cFormat; diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index da33f80035..5147266c99 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -215,7 +215,7 @@ static void WriteBmp(const char* pdf_name, int num, const void* buffer, if (!fp) return; - BITMAPINFO bmi = {0}; + BITMAPINFO bmi = {}; bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; // top-down image @@ -224,7 +224,7 @@ static void WriteBmp(const char* pdf_name, int num, const void* buffer, bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; - BITMAPFILEHEADER file_header = {0}; + BITMAPFILEHEADER file_header = {}; file_header.bfType = 0x4d42; file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len; file_header.bfOffBits = file_header.bfSize - out_len; diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn index 5e7dd5f575..37e30ce06d 100644 --- a/third_party/BUILD.gn +++ b/third_party/BUILD.gn @@ -95,10 +95,18 @@ source_set("fx_agg") { } source_set("fx_lcms2") { + config("fx_lcms2_warnings") { + if (is_clang) { + # cmslut.cc is sloppy with aggregate initialization. Version 2.7 of this + # library doesn't appear to have this problem. + cflags = [ "-Wno-missing-braces" ] + } + } configs -= [ "//build/config/compiler:chromium_code" ] configs += [ "//build/config/compiler:no_chromium_code", "//third_party/pdfium:pdfium_config", + ":fx_lcms2_warnings", ] sources = [ "lcms2-2.6/include/lcms2.h", diff --git a/third_party/third_party.gyp b/third_party/third_party.gyp index 3446439aa4..79368b5a68 100644 --- a/third_party/third_party.gyp +++ b/third_party/third_party.gyp @@ -137,6 +137,11 @@ ], }], ], + 'variables': { + 'clang_warning_flags': [ + '-Wno-missing-braces', + ], + }, }, { 'target_name': 'fx_libjpeg', -- cgit v1.2.3