Skip to content

Commit

Permalink
Fix some clang warnings with -Wmissing-braces in base.
Browse files Browse the repository at this point in the history
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.

BUG=505297

Review URL: https://codereview.chromium.org/1218243002

Cr-Commit-Position: refs/heads/master@{#337139}
  • Loading branch information
zetafunction authored and Commit bot committed Jul 2, 2015
1 parent 887c3cd commit e74809c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 57 deletions.
76 changes: 36 additions & 40 deletions base/file_version_info_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,49 @@ FilePath GetTestDataPath() {

#if defined(OS_WIN)
TEST(FileVersionInfoTest, HardCodedProperties) {
const wchar_t* kDLLNames[] = {
L"FileVersionInfoTest1.dll"
};
const wchar_t kDLLName[] = {L"FileVersionInfoTest1.dll"};

const wchar_t* kExpectedValues[1][15] = {
const wchar_t* const kExpectedValues[15] = {
// FileVersionInfoTest.dll
L"Goooooogle", // company_name
L"Google", // company_short_name
L"This is the product name", // product_name
L"This is the product short name", // product_short_name
L"The Internal Name", // internal_name
L"4.3.2.1", // product_version
L"Private build property", // private_build
L"Special build property", // special_build
L"Goooooogle", // company_name
L"Google", // company_short_name
L"This is the product name", // product_name
L"This is the product short name", // product_short_name
L"The Internal Name", // internal_name
L"4.3.2.1", // product_version
L"Private build property", // private_build
L"Special build property", // special_build
L"This is a particularly interesting comment", // comments
L"This is the original filename", // original_filename
L"This is my file description", // file_description
L"1.2.3.4", // file_version
L"This is the legal copyright", // legal_copyright
L"This is the legal trademarks", // legal_trademarks
L"This is the last change", // last_change
L"This is the original filename", // original_filename
L"This is my file description", // file_description
L"1.2.3.4", // file_version
L"This is the legal copyright", // legal_copyright
L"This is the legal trademarks", // legal_trademarks
L"This is the last change", // last_change
};

for (int i = 0; i < arraysize(kDLLNames); ++i) {
FilePath dll_path = GetTestDataPath();
dll_path = dll_path.Append(kDLLNames[i]);
FilePath dll_path = GetTestDataPath();
dll_path = dll_path.Append(kDLLName);

scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(dll_path));
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(dll_path));

int j = 0;
EXPECT_EQ(kExpectedValues[i][j++], version_info->company_name());
EXPECT_EQ(kExpectedValues[i][j++], version_info->company_short_name());
EXPECT_EQ(kExpectedValues[i][j++], version_info->product_name());
EXPECT_EQ(kExpectedValues[i][j++], version_info->product_short_name());
EXPECT_EQ(kExpectedValues[i][j++], version_info->internal_name());
EXPECT_EQ(kExpectedValues[i][j++], version_info->product_version());
EXPECT_EQ(kExpectedValues[i][j++], version_info->private_build());
EXPECT_EQ(kExpectedValues[i][j++], version_info->special_build());
EXPECT_EQ(kExpectedValues[i][j++], version_info->comments());
EXPECT_EQ(kExpectedValues[i][j++], version_info->original_filename());
EXPECT_EQ(kExpectedValues[i][j++], version_info->file_description());
EXPECT_EQ(kExpectedValues[i][j++], version_info->file_version());
EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_copyright());
EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_trademarks());
EXPECT_EQ(kExpectedValues[i][j++], version_info->last_change());
}
int j = 0;
EXPECT_EQ(kExpectedValues[j++], version_info->company_name());
EXPECT_EQ(kExpectedValues[j++], version_info->company_short_name());
EXPECT_EQ(kExpectedValues[j++], version_info->product_name());
EXPECT_EQ(kExpectedValues[j++], version_info->product_short_name());
EXPECT_EQ(kExpectedValues[j++], version_info->internal_name());
EXPECT_EQ(kExpectedValues[j++], version_info->product_version());
EXPECT_EQ(kExpectedValues[j++], version_info->private_build());
EXPECT_EQ(kExpectedValues[j++], version_info->special_build());
EXPECT_EQ(kExpectedValues[j++], version_info->comments());
EXPECT_EQ(kExpectedValues[j++], version_info->original_filename());
EXPECT_EQ(kExpectedValues[j++], version_info->file_description());
EXPECT_EQ(kExpectedValues[j++], version_info->file_version());
EXPECT_EQ(kExpectedValues[j++], version_info->legal_copyright());
EXPECT_EQ(kExpectedValues[j++], version_info->legal_trademarks());
EXPECT_EQ(kExpectedValues[j++], version_info->last_change());
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion base/files/memory_mapped_file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool MemoryMappedFile::MapFileRegionToMemory(
if (!file_mapping_.IsValid())
return false;

LARGE_INTEGER map_start = {0};
LARGE_INTEGER map_start = {};
SIZE_T map_size = 0;
int32 data_offset = 0;

Expand Down
4 changes: 2 additions & 2 deletions base/process/launch_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Process LaunchElevatedProcess(const CommandLine& cmdline,
const string16 file = cmdline.GetProgram().value();
const string16 arguments = cmdline.GetArgumentsString();

SHELLEXECUTEINFO shex_info = {0};
SHELLEXECUTEINFO shex_info = {};
shex_info.cbSize = sizeof(shex_info);
shex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
shex_info.hwnd = GetActiveWindow();
Expand All @@ -261,7 +261,7 @@ Process LaunchElevatedProcess(const CommandLine& cmdline,
}

bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) {
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {};
limit_info.BasicLimitInformation.LimitFlags = limit_flags;
return 0 != SetInformationJobObject(
job_object,
Expand Down
2 changes: 1 addition & 1 deletion base/profiler/stack_sampling_profiler_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int RecordStack(CONTEXT* context,
instruction_pointers[i] = reinterpret_cast<const void*>(context->Rip);

if (runtime_function) {
KNONVOLATILE_CONTEXT_POINTERS nvcontext = {0};
KNONVOLATILE_CONTEXT_POINTERS nvcontext = {};
void* handler_data;
ULONG64 establisher_frame;
RtlVirtualUnwind(0, image_base, context->Rip, runtime_function, context,
Expand Down
6 changes: 3 additions & 3 deletions base/third_party/nspr/prtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
static const PRTime kSecondsToMicroseconds = static_cast<PRTime>(1000000);
#if defined(OS_WIN)
// Create the system struct representing our exploded time.
SYSTEMTIME st = {0};
FILETIME ft = {0};
ULARGE_INTEGER uli = {0};
SYSTEMTIME st = {};
FILETIME ft = {};
ULARGE_INTEGER uli = {};

st.wYear = exploded->tm_year;
st.wMonth = static_cast<WORD>(exploded->tm_month + 1);
Expand Down
2 changes: 1 addition & 1 deletion base/time/time_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ bool IsBuggyAthlon(const base::CPU& cpu) {
}

void InitializeNowFunctionPointers() {
LARGE_INTEGER ticks_per_sec = {0};
LARGE_INTEGER ticks_per_sec = {};
if (!QueryPerformanceFrequency(&ticks_per_sec))
ticks_per_sec.QuadPart = 0;

Expand Down
16 changes: 12 additions & 4 deletions base/trace_event/trace_event_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ using base::win::EtwMofEvent;

// {3DADA31D-19EF-4dc1-B345-037927193422}
const GUID kChromeTraceProviderName = {
0x3dada31d, 0x19ef, 0x4dc1, 0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22 };
0x3dada31d,
0x19ef,
0x4dc1,
{0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22}};

// {B967AE67-BB22-49d7-9406-55D91EE1D560}
const GUID kTraceEventClass32 = {
0xb967ae67, 0xbb22, 0x49d7, 0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60 };
0xb967ae67,
0xbb22,
0x49d7,
{0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60}};

// {97BE602D-2930-4ac3-8046-B6763B631DFE}
const GUID kTraceEventClass64 = {
0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe};

0x97be602d,
0x2930,
0x4ac3,
{0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe}};

TraceEventETWProvider::TraceEventETWProvider() :
EtwTraceProvider(kChromeTraceProviderName) {
Expand Down
6 changes: 4 additions & 2 deletions base/win/scoped_comptr_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ struct Dummy {
};

extern const IID dummy_iid;
const IID dummy_iid = { 0x12345678u, 0x1234u, 0x5678u, 01, 23, 45, 67, 89,
01, 23, 45 };
const IID dummy_iid = {0x12345678u,
0x1234u,
0x5678u,
{01, 23, 45, 67, 89, 01, 23, 45}};

} // namespace

Expand Down
4 changes: 2 additions & 2 deletions base/win/scoped_variant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace base {
namespace win {

// Global, const instance of an empty variant.
const VARIANT ScopedVariant::kEmptyVariant = { VT_EMPTY };
const VARIANT ScopedVariant::kEmptyVariant = {{{VT_EMPTY}}};

ScopedVariant::~ScopedVariant() {
COMPILE_ASSERT(sizeof(ScopedVariant) == sizeof(VARIANT), ScopedVariantSize);
Expand Down Expand Up @@ -82,7 +82,7 @@ VARIANT* ScopedVariant::Receive() {
}

VARIANT ScopedVariant::Copy() const {
VARIANT ret = { VT_EMPTY };
VARIANT ret = {{{VT_EMPTY}}};
::VariantCopy(&ret, &var_);
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion base/win/windows_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ OSInfo::OSInfo()
service_pack_.major = version_info.wServicePackMajor;
service_pack_.minor = version_info.wServicePackMinor;

SYSTEM_INFO system_info = { 0 };
SYSTEM_INFO system_info = {};
::GetNativeSystemInfo(&system_info);
switch (system_info.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break;
Expand Down

0 comments on commit e74809c

Please sign in to comment.