Skip to content

Commit

Permalink
Bug 1204403 - Fix -Wshadow warnings in xpcom. r=mccr8
Browse files Browse the repository at this point in the history
  • Loading branch information
cpeterso committed Sep 8, 2015
1 parent bfd0628 commit 0dbaae1
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 187 deletions.
33 changes: 17 additions & 16 deletions xpcom/base/SystemMemoryReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ class SystemReporter final : public nsIMemoryReporter
do { \
size_t amount = _amount; /* evaluate _amount only once */ \
if (amount > 0) { \
nsresult rv; \
rv = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \
nsresult rvReport; \
rvReport = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \
KIND_NONHEAP, _units, amount, _desc, \
aData); \
if (NS_WARN_IF(NS_FAILED(rv))) { \
if (NS_WARN_IF(NS_FAILED(rvReport))) { \
_cleanup; \
return rv; \
return rvReport; \
} \
} \
} while (0)
Expand Down Expand Up @@ -373,23 +373,24 @@ class SystemReporter final : public nsIMemoryReporter
char devMinor[17];
unsigned int inode;
char line[1025];

// This variable holds the path of the current entry, or is void
// if we're scanning for the start of a new entry.
nsAutoCString path;
nsAutoCString currentPath;
int pathOffset;

path.SetIsVoid(true);
currentPath.SetIsVoid(true);
while (fgets(line, sizeof(line), aFile)) {
if (path.IsVoid()) {
if (currentPath.IsVoid()) {
int n = sscanf(line,
"%llx-%llx %4s %llx "
"%16[0-9a-fA-F]:%16[0-9a-fA-F] %u %n",
&addrStart, &addrEnd, perms, &offset, devMajor,
devMinor, &inode, &pathOffset);

if (n >= argCount - 1) {
path.Assign(line + pathOffset);
path.StripChars("\n");
currentPath.Assign(line + pathOffset);
currentPath.StripChars("\n");
}
continue;
}
Expand All @@ -404,22 +405,22 @@ class SystemReporter final : public nsIMemoryReporter
size_t pss = pss_kb * 1024;
if (pss > 0) {
nsAutoCString name, description, tag;
GetReporterNameAndDescription(path.get(), perms, name, description, tag);
GetReporterNameAndDescription(currentPath.get(), perms, name, description, tag);

nsAutoCString path("mem/processes/");
path.Append(aProcessName);
path.Append('/');
path.Append(name);
nsAutoCString processMemPath("mem/processes/");
processMemPath.Append(aProcessName);
processMemPath.Append('/');
processMemPath.Append(name);

REPORT(path, pss, description);
REPORT(processMemPath, pss, description);

// Increment the appropriate aProcessSizes values, and the total.
aProcessSizes->Add(tag, pss);
*aTotalPss += pss;
}

// Now that we've seen the PSS, we're done with this entry.
path.SetIsVoid(true);
currentPath.SetIsVoid(true);
}
return NS_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions xpcom/base/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ LOCAL_INCLUDES += [

if CONFIG['MOZ_WIDGET_GTK']:
CXXFLAGS += CONFIG['TK_CFLAGS']

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']
6 changes: 3 additions & 3 deletions xpcom/base/nsStatusReporterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ NS_STATUS_REPORTER_IMPLEMENT(StatusReporter, "StatusReporter State", getStatus)
do { \
const char* s2 = (s); \
uint32_t dummy; \
nsresult rv = (o)->Write((s2), strlen(s2), &dummy); \
if (NS_WARN_IF(NS_FAILED(rv))) \
return rv; \
nsresult rvDump = (o)->Write((s2), strlen(s2), &dummy); \
if (NS_WARN_IF(NS_FAILED(rvDump))) \
return rvDump; \
} while (0)

static nsresult
Expand Down
1 change: 1 addition & 0 deletions xpcom/build/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ SOURCES += [

if CONFIG['GNU_CC']:
CFLAGS += ['-Wshadow']
CXXFLAGS += ['-Wshadow']

include('/ipc/chromium/chromium-config.mozbuild')

Expand Down
3 changes: 3 additions & 0 deletions xpcom/ds/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ LOCAL_INCLUDES += [
]

FINAL_LIBRARY = 'xul'

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']
6 changes: 3 additions & 3 deletions xpcom/ds/nsVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,9 @@ nsDiscriminatedUnion::ConvertToStringWithSize(uint32_t* aSize, char** aStr) cons
// *aSize = *mUTF8StringValue->Length();
// *aStr = ToNewCString(*mUTF8StringValue);
// But this will have to do for now.
NS_ConvertUTF8toUTF16 tempString(*u.mUTF8StringValue);
*aSize = tempString.Length();
*aStr = ToNewCString(tempString);
const NS_ConvertUTF8toUTF16 tempString16(*u.mUTF8StringValue);
*aSize = tempString16.Length();
*aStr = ToNewCString(tempString16);
break;
}
case nsIDataType::VTYPE_CHAR_STR: {
Expand Down
14 changes: 7 additions & 7 deletions xpcom/glue/GenericModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
const char* aLoaderStr,
const char* aType)
{
nsCOMPtr<nsIComponentRegistrar> r = do_QueryInterface(aCompMgr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr);
for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) {
r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation,
aLoaderStr, aType);
registrar->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation,
aLoaderStr, aType);
}

for (const Module::ContractIDEntry* e = mData->mContractIDs;
e && e->contractid;
++e) {
r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation,
aLoaderStr, aType);
registrar->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation,
aLoaderStr, aType);
}

nsCOMPtr<nsICategoryManager> catman;
Expand All @@ -71,9 +71,9 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
}

nsAutoCString r;
nsAutoCString prevValue;
catman->AddCategoryEntry(e->category, e->entry, e->value, true, true,
getter_Copies(r));
getter_Copies(prevValue));
}
return NS_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions xpcom/glue/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ USE_LIBS += [
NO_EXPAND_LIBS = True

DIST_INSTALL = True

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']
18 changes: 8 additions & 10 deletions xpcom/glue/nsCRTGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,19 @@ NS_IsAsciiDigit(char16_t aChar)
return aChar >= '0' && aChar <= '9';
}


#ifndef XPCOM_GLUE_AVOID_NSPR
#define TABLE_SIZE 36
static const char table[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9'
};

void
NS_MakeRandomString(char* aBuf, int32_t aBufLen)
{
#define TABLE_SIZE 36
static const char table[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9'
};

// turn PR_Now() into milliseconds since epoch
// and salt rand with that.
static unsigned int seed = 0;
Expand Down Expand Up @@ -435,5 +435,3 @@ fprintf_stderr(FILE* aFile, const char* aFmt, ...)
}
va_end(args);
}


4 changes: 2 additions & 2 deletions xpcom/glue/nsTArray-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ nsTArray_base<Alloc, Copy>::ShiftData(index_type aStart,
aStart *= aElemSize;
aNewLen *= aElemSize;
aOldLen *= aElemSize;
char* base = reinterpret_cast<char*>(mHdr + 1) + aStart;
Copy::MoveElements(base + aNewLen, base + aOldLen, num, aElemSize);
char* baseAddr = reinterpret_cast<char*>(mHdr + 1) + aStart;
Copy::MoveElements(baseAddr + aNewLen, baseAddr + aOldLen, num, aElemSize);
}
}

Expand Down
Loading

0 comments on commit 0dbaae1

Please sign in to comment.