Skip to content

Commit

Permalink
Bug 1628715 - Part 15: Replace MOZ_NONNULL_RETURN by returning NotNul…
Browse files Browse the repository at this point in the history
…l<elem_type*>. r=xpcom-reviewers,necko-reviewers,dragana,nika

Differential Revision: https://phabricator.services.mozilla.com/D71300
  • Loading branch information
sigiesec committed Apr 24, 2020
1 parent 9a01796 commit 2d8c439
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 149 deletions.
2 changes: 1 addition & 1 deletion docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ bool BrowsingContext::HasOpener() const {
}

void BrowsingContext::GetChildren(Children& aChildren) {
MOZ_ALWAYS_TRUE(aChildren.AppendElements(mChildren));
aChildren.AppendElements(mChildren);
}

void BrowsingContext::GetWindowContexts(
Expand Down
4 changes: 1 addition & 3 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12062,9 +12062,7 @@ nsresult Document::ScheduleFrameRequestCallback(FrameRequestCallback& aCallback,
}
int32_t newHandle = ++mFrameRequestCallbackCounter;

DebugOnly<FrameRequest*> request =
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
UpdateFrameRequestCallbackSchedulingState();

*aHandle = newHandle;
Expand Down
35 changes: 17 additions & 18 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10025,14 +10025,14 @@ struct CommonPopulateResponseHelper {
}

template <typename Response>
void FillKeys(Response* const aResponse) {
void FillKeys(Response& aResponse) {
MOZ_ASSERT(!mPosition.IsUnset());
aResponse->key() = std::move(mPosition);
aResponse.key() = std::move(mPosition);
}

template <typename Response>
static size_t GetKeySize(const Response* const aResponse) {
return aResponse->key().GetBuffer().Length();
static size_t GetKeySize(const Response& aResponse) {
return aResponse.key().GetBuffer().Length();
}

protected:
Expand Down Expand Up @@ -10075,20 +10075,20 @@ struct IndexPopulateResponseHelper : CommonPopulateResponseHelper {
}

template <typename Response>
void FillKeys(Response* const aResponse) {
void FillKeys(Response& aResponse) {
MOZ_ASSERT(!mLocaleAwarePosition.IsUnset());
MOZ_ASSERT(!mObjectStorePosition.IsUnset());

CommonPopulateResponseHelper::FillKeys(aResponse);
aResponse->sortKey() = std::move(mLocaleAwarePosition);
aResponse->objectKey() = std::move(mObjectStorePosition);
aResponse.sortKey() = std::move(mLocaleAwarePosition);
aResponse.objectKey() = std::move(mObjectStorePosition);
}

template <typename Response>
static size_t GetKeySize(const Response* const aResponse) {
static size_t GetKeySize(Response& aResponse) {
return CommonPopulateResponseHelper::GetKeySize(aResponse) +
aResponse->sortKey().GetBuffer().Length() +
aResponse->objectKey().GetBuffer().Length();
aResponse.sortKey().GetBuffer().Length() +
aResponse.objectKey().GetBuffer().Length();
}

private:
Expand All @@ -10102,12 +10102,11 @@ struct KeyPopulateResponseHelper {
}

template <typename Response>
static constexpr void MaybeFillCloneInfo(Response* const /*aResponse*/,
static constexpr void MaybeFillCloneInfo(Response& /*aResponse*/,
FilesArray* const /*aFiles*/) {}

template <typename Response>
static constexpr size_t MaybeGetCloneInfoSize(
const Response* const /*aResponse*/) {
static constexpr size_t MaybeGetCloneInfoSize(const Response& /*aResponse*/) {
return 0;
}
};
Expand Down Expand Up @@ -10138,15 +10137,15 @@ struct ValuePopulateResponseHelper {
}

template <typename Response>
void MaybeFillCloneInfo(Response* const aResponse, FilesArray* const aFiles) {
void MaybeFillCloneInfo(Response& aResponse, FilesArray* const aFiles) {
auto cloneInfo = mCloneInfo.release();
aResponse->cloneInfo().data().data = cloneInfo.ReleaseData();
aResponse.cloneInfo().data().data = cloneInfo.ReleaseData();
aFiles->AppendElement(cloneInfo.ReleaseFiles());
}

template <typename Response>
static size_t MaybeGetCloneInfoSize(const Response* const aResponse) {
return aResponse->cloneInfo().data().data.Size();
static size_t MaybeGetCloneInfoSize(const Response& aResponse) {
return aResponse.cloneInfo().data().data.Size();
}

private:
Expand Down Expand Up @@ -26744,7 +26743,7 @@ CursorOpBaseHelperBase<CursorType>::PopulateResponseFromStatement(
}

auto& responses = populateResponseHelper.GetTypedResponse(&mOp.mResponse);
auto* response = responses.AppendElement();
auto& response = *responses.AppendElement();

populateResponseHelper.FillKeys(response);
if constexpr (!CursorTypeTraits<CursorType>::IsKeyOnlyCursor) {
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/JSWindowActorService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ JSWindowActorProtocol::FromIPC(const JSWindowActorInfo& aInfo) {

proto->mChild.mEvents.SetCapacity(aInfo.events().Length());
for (auto& ipc : aInfo.events()) {
auto* event = proto->mChild.mEvents.AppendElement();
auto event = proto->mChild.mEvents.AppendElement();
event->mName.Assign(ipc.name());
event->mFlags.mCapture = ipc.capture();
event->mFlags.mInSystemGroup = ipc.systemGroup();
Expand All @@ -79,7 +79,7 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() {

info.events().SetCapacity(mChild.mEvents.Length());
for (auto& event : mChild.mEvents) {
auto* ipc = info.events().AppendElement();
auto ipc = info.events().AppendElement();
ipc->name().Assign(event.mName);
ipc->capture() = event.mFlags.mCapture;
ipc->systemGroup() = event.mFlags.mInSystemGroup;
Expand Down Expand Up @@ -312,7 +312,7 @@ extensions::MatchPatternSet* JSWindowActorProtocol::GetURIMatcher() {
nsTArray<OwningStringOrMatchPattern> patterns;
patterns.SetCapacity(mMatches.Length());
for (nsString& s : mMatches) {
auto* entry = patterns.AppendElement();
auto entry = patterns.AppendElement();
entry->SetAsString() = s;
}

Expand Down
4 changes: 1 addition & 3 deletions dom/vr/XRSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ int32_t XRSession::RequestAnimationFrame(XRFrameRequestCallback& aCallback,

int32_t handle = ++mFrameRequestCallbackCounter;

DebugOnly<XRFrameRequest*> request =
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle));

return handle;
}
Expand Down
4 changes: 1 addition & 3 deletions gfx/vr/ipc/VRManagerChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ nsresult VRManagerChild::ScheduleFrameRequestCallback(
}
int32_t newHandle = ++mFrameRequestCallbackCounter;

DebugOnly<XRFrameRequest*> request = mFrameRequestCallbacks.AppendElement(
XRFrameRequest(aCallback, newHandle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, newHandle));

*aHandle = newHandle;
return NS_OK;
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsGridContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::GridReflowInput {
uint32_t offsetInOppositeAxis = aRangeInOppositeAxis.mStart;
uint32_t gridEndInOppositeAxis = aRangeInOppositeAxis.Extent();
for (const auto& subgridItem : aItems) {
auto* newItem = aResult.AppendElement(
auto newItem = aResult.AppendElement(
isOrthogonal ? subgridItem.Transpose() : subgridItem);
if (MOZ_UNLIKELY(!isSameDirInAxis)) {
newItem->ReverseDirection(aAxis, gridEndInAxis);
Expand Down
4 changes: 1 addition & 3 deletions layout/printing/nsPrintJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
aIsPrintPreview);
NS_ENSURE_SUCCESS(rv, rv);

NS_ENSURE_TRUE(
printData->mPrintDocList.AppendElement(printData->mPrintObject.get()),
NS_ERROR_OUT_OF_MEMORY);
printData->mPrintDocList.AppendElement(printData->mPrintObject.get());

printData->mIsParentAFrameSet = IsParentAFrameSet(docShell);
printData->mPrintObject->mFrameType =
Expand Down
17 changes: 6 additions & 11 deletions layout/tables/nsCellMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,10 @@ bool nsCellMap::Grow(nsTableCellMap& aMap, int32_t aNumRows,
uint32_t startRowIndex = (aRowIndex >= 0) ? aRowIndex : mRows.Length();
NS_ASSERTION(startRowIndex <= mRows.Length(), "Missing grow call inbetween");

return mRows.InsertElementsAt(startRowIndex, aNumRows, numCols) != nullptr;
// XXX Change the return type of this function to void, or use a fallible
// operation.
mRows.InsertElementsAt(startRowIndex, aNumRows, numCols);
return true;
}

void nsCellMap::GrowRow(CellDataArray& aRow, int32_t aNumCols)
Expand Down Expand Up @@ -1642,16 +1645,8 @@ void nsCellMap::ExpandWithCells(nsTableCellMap& aMap,
if (insertionIndex > startColIndex) {
insertionIndex = startColIndex;
}
if (!row.InsertElementsAt(insertionIndex,
endColIndex - insertionIndex + 1,
(CellData*)nullptr) &&
rowX == aRowIndex) {
// Failed to insert the slots, and this is the very first row. That
// means that we need to clean up |origData| before returning, since
// the cellmap doesn't own it yet.
DestroyCellData(origData);
return;
}
row.InsertElementsAt(insertionIndex, endColIndex - insertionIndex + 1,
(CellData*)nullptr);

for (int32_t colX = startColIndex; colX <= endColIndex; colX++) {
CellData* data = origData;
Expand Down
9 changes: 9 additions & 0 deletions mfbt/PodOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace mozilla {

template <typename T>
class NotNull;

/** Set the contents of |aT| to 0. */
template <typename T>
static MOZ_ALWAYS_INLINE void PodZero(T* aT) {
Expand All @@ -44,6 +47,12 @@ static MOZ_ALWAYS_INLINE void PodZero(T* aT, size_t aNElem) {
}
}

/** Set the contents of |aNElem| elements starting at |aT| to 0. */
template <typename T>
static MOZ_ALWAYS_INLINE void PodZero(NotNull<T*> aT, size_t aNElem) {
PodZero(aT.get(), aNElem);
}

/*
* Arrays implicitly convert to pointers to their first element, which is
* dangerous when combined with the above PodZero definitions. Adding an
Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/nsFileStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void nsFileInputStream::SerializeInternal(
FileHandleType fd = FileHandleType(PR_FileDesc2NativeHandle(mFD));
NS_ASSERTION(fd, "This should never be null!");

DebugOnly<FileDescriptor*> dbgFD = aFileDescriptors.AppendElement(fd);
DebugOnly dbgFD = aFileDescriptors.AppendElement(fd);
NS_ASSERTION(dbgFD->IsValid(), "Sending an invalid file descriptor!");

params.fileDescriptorIndex() = aFileDescriptors.Length() - 1;
Expand Down
2 changes: 1 addition & 1 deletion storage/StorageBaseStatementInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ StorageBaseStatementInternal::ExecuteAsync(
StatementData data;
nsresult rv = getAsynchronousStatementData(data);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY);
stmts.AppendElement(data);

// Dispatch to the background
return AsyncExecuteStatements::execute(stmts, mDBConnection,
Expand Down
6 changes: 2 additions & 4 deletions storage/mozStorageBindingParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ BindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) {
(void)mParameters.SetLength(aIndex);
(void)mParameters.AppendElement(variant);
} else {
NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant),
NS_ERROR_OUT_OF_MEMORY);
mParameters.ReplaceElementAt(aIndex, variant);
}
return NS_OK;
}
Expand All @@ -335,8 +334,7 @@ AsyncBindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) {
mParameters.SetLength(aIndex);
mParameters.AppendElement(variant);
} else {
NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant),
NS_ERROR_OUT_OF_MEMORY);
mParameters.ReplaceElementAt(aIndex, variant);
}
return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion storage/mozStorageBindingParamsArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ BindingParamsArray::AddParams(mozIStorageBindingParams* aParameters) {
// Check to make sure that this set of parameters was created with us.
if (params->getOwner() != this) return NS_ERROR_UNEXPECTED;

NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY);
mArray.AppendElement(params);

// Lock the parameters only after we've successfully added them.
params->lock();
Expand Down
2 changes: 1 addition & 1 deletion storage/mozStorageConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ Connection::ExecuteAsync(
"Statement must be from this database connection!");

// Now append it to our array.
NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY);
stmts.AppendElement(data);
}

// Dispatch to the background
Expand Down
3 changes: 1 addition & 2 deletions toolkit/components/places/History.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,8 +1855,7 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI,
}

nsTArray<VisitData> placeArray(1);
NS_ENSURE_TRUE(placeArray.AppendElement(VisitData(aURI, aLastVisitedURI)),
NS_ERROR_OUT_OF_MEMORY);
placeArray.AppendElement(VisitData(aURI, aLastVisitedURI));
VisitData& place = placeArray.ElementAt(0);
NS_ENSURE_FALSE(place.spec.IsEmpty(), NS_ERROR_INVALID_ARG);

Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/places/nsNavBookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ nsresult nsNavBookmarks::GetBookmarksForURI(
rv = stmt->GetInt32(6, &bookmark.syncStatus);
NS_ENSURE_SUCCESS(rv, rv);

NS_ENSURE_TRUE(aBookmarks.AppendElement(bookmark), NS_ERROR_OUT_OF_MEMORY);
aBookmarks.AppendElement(bookmark);
}

return NS_OK;
Expand Down
7 changes: 3 additions & 4 deletions toolkit/components/places/nsNavHistoryQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,

// parent folders (guids)
} else if (kvp.key.EqualsLiteral(QUERYKEY_PARENT)) {
NS_ENSURE_TRUE(parents.AppendElement(kvp.value), NS_ERROR_OUT_OF_MEMORY);
parents.AppendElement(kvp.value);

// uri
} else if (kvp.key.EqualsLiteral(QUERYKEY_URI)) {
Expand Down Expand Up @@ -462,7 +462,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
NS_UnescapeURL(unescaped); // modifies input
NS_ConvertUTF8toUTF16 tag(unescaped);
if (!tags.Contains(tag)) {
NS_ENSURE_TRUE(tags.AppendElement(tag), NS_ERROR_OUT_OF_MEMORY);
tags.AppendElement(tag);
}

// not tags
Expand All @@ -474,8 +474,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
uint32_t transition = kvp.value.ToInteger(&rv);
if (NS_SUCCEEDED(rv)) {
if (!transitions.Contains(transition))
NS_ENSURE_TRUE(transitions.AppendElement(transition),
NS_ERROR_OUT_OF_MEMORY);
transitions.AppendElement(transition);
} else {
NS_WARNING("Invalid Int32 transition value.");
}
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/reputationservice/LoginReputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ LoginReputationService::QueryReputation(
// mQueryRequests is an array used to maintain the ownership of
// |QueryRequest|. We ensure that |QueryRequest| is always valid until
// Finish() is called or LoginReputationService is shutdown.
auto* request =
auto request =
mQueryRequests.AppendElement(MakeUnique<QueryRequest>(aQuery, aCallback));

return QueryLoginWhitelist(request->get());
Expand Down
Loading

0 comments on commit 2d8c439

Please sign in to comment.