gecko-dev/toolkit/xre/CreateAppData.cpp
Chris Peterson f6bbb6a455 Bug 1356843 - Fix -Wcomma warnings in toolkit/. r=mossop
clang's -Wcomma warning warns about suspicious use of the comma operator such as between two statements or calling a function for side effects within an expression. Check NS_SUCCEEDED() to use HasMoreElement() in an expression and confirm that it actually returned a legitimate out parameter.

toolkit/components/startup/nsAppStartup.cpp:436:58 [-Wcomma] possible misuse of comma operator here
toolkit/components/statusfilter/nsBrowserStatusFilter.cpp:165:66 [-Wcomma] possible misuse of comma operator here
toolkit/xre/CreateAppData.cpp:60:51 [-Wcomma] possible misuse of comma operator here

MozReview-Commit-ID: HuZRoOjQTGj

--HG--
extra : rebase_source : c159e26d619b960163fda11069e722010a21d2f8
extra : source : c405a2ab8ec4b6b96373fe3812a6d30bb0641d6f
2017-04-05 01:23:45 -07:00

78 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsXULAppAPI.h"
#include "nsINIParser.h"
#include "nsIFile.h"
#include "nsAutoPtr.h"
#include "mozilla/XREAppData.h"
using namespace mozilla;
static void
ReadString(nsINIParser &parser, const char* section,
const char* key, XREAppData::CharPtr& result)
{
nsCString str;
nsresult rv = parser.GetString(section, key, str);
if (NS_SUCCEEDED(rv)) {
result = str.get();
}
}
struct ReadFlag {
const char *section;
const char *key;
uint32_t flag;
};
static void
ReadFlag(nsINIParser &parser, const char* section,
const char* key, uint32_t flag, uint32_t& result)
{
char buf[6]; // large enough to hold "false"
nsresult rv = parser.GetString(section, key, buf, sizeof(buf));
if (NS_SUCCEEDED(rv) || rv == NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
if (buf[0] == '1' || buf[0] == 't' || buf[0] == 'T') {
result |= flag;
}
if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
result &= ~flag;
}
}
}
nsresult
XRE_ParseAppData(nsIFile* aINIFile, XREAppData& aAppData)
{
NS_ENSURE_ARG(aINIFile);
nsresult rv;
nsINIParser parser;
rv = parser.Init(aINIFile);
if (NS_FAILED(rv))
return rv;
ReadString(parser, "App", "Vendor", aAppData.vendor);
ReadString(parser, "App", "Name", aAppData.name);
ReadString(parser, "App", "RemotingName", aAppData.remotingName);
ReadString(parser, "App", "Version", aAppData.version);
ReadString(parser, "App", "BuildID", aAppData.buildID);
ReadString(parser, "App", "ID", aAppData.ID);
ReadString(parser, "App", "Copyright", aAppData.copyright);
ReadString(parser, "App", "Profile", aAppData.profile);
ReadString(parser, "Gecko", "MinVersion", aAppData.minVersion);
ReadString(parser, "Gecko", "MaxVersion", aAppData.maxVersion);
ReadString(parser, "Crash Reporter", "ServerURL", aAppData.crashReporterURL);
ReadString(parser, "App", "UAName", aAppData.UAName);
ReadFlag(parser, "XRE", "EnableProfileMigrator",
NS_XRE_ENABLE_PROFILE_MIGRATOR, aAppData.flags);
ReadFlag(parser, "Crash Reporter", "Enabled",
NS_XRE_ENABLE_CRASH_REPORTER, aAppData.flags);
return NS_OK;
}