Bug 1886922: Do not dereference a Maybe if it is not Some r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D205409
This commit is contained in:
Tom Ritter 2024-03-22 15:32:39 +00:00
parent 0aed52d2bb
commit 06692a4fe7
4 changed files with 46 additions and 16 deletions

View file

@ -8093,7 +8093,7 @@ IPCResult ContentParent::RecvRawMessage(
stack->BorrowFromClonedMessageData(*aStack);
}
MMPrinter::Print("ContentParent::RecvRawMessage", aMeta.actorName(),
aMeta.messageName(), *aData);
aMeta.messageName(), aData);
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
return IPC_OK();
}

View file

@ -26,8 +26,8 @@ LazyLogModule MMPrinter::sMMLog("MessageManager");
// the output of the logs into logs more friendly to reading.
/* static */
void MMPrinter::PrintImpl(char const* aLocation, const nsAString& aMsg,
ClonedMessageData const& aData) {
Maybe<uint64_t> MMPrinter::PrintHeader(char const* aLocation,
const nsAString& aMsg) {
NS_ConvertUTF16toUTF8 charMsg(aMsg);
/*
@ -43,15 +43,29 @@ void MMPrinter::PrintImpl(char const* aLocation, const nsAString& aMsg,
char* mmSkipLog = PR_GetEnv("MOZ_LOG_MESSAGEMANAGER_SKIP");
if (mmSkipLog && strstr(mmSkipLog, charMsg.get())) {
return;
return Nothing();
}
uint64_t msg_id = RandomUint64OrDie();
uint64_t aMsgId = RandomUint64OrDie();
MOZ_LOG(MMPrinter::sMMLog, LogLevel::Debug,
("%" PRIu64 " %s Message: %s in process type: %s", msg_id, aLocation,
("%" PRIu64 " %s Message: %s in process type: %s", aMsgId, aLocation,
charMsg.get(), XRE_GetProcessTypeString()));
return Some(aMsgId);
}
/* static */
void MMPrinter::PrintNoData(uint64_t aMsgId) {
if (!MOZ_LOG_TEST(sMMLog, LogLevel::Verbose)) {
return;
}
MOZ_LOG(MMPrinter::sMMLog, LogLevel::Verbose,
("%" PRIu64 " (No Data)", aMsgId));
}
/* static */
void MMPrinter::PrintData(uint64_t aMsgId, ClonedMessageData const& aData) {
if (!MOZ_LOG_TEST(sMMLog, LogLevel::Verbose)) {
return;
}
@ -75,8 +89,7 @@ void MMPrinter::PrintImpl(char const* aLocation, const nsAString& aMsg,
if (rv.Failed()) {
// In testing, the only reason this would fail was if there was no data in
// the message; so it seems like this is safe-ish.
MOZ_LOG(MMPrinter::sMMLog, LogLevel::Verbose,
("%" PRIu64 " (No Data)", msg_id));
MMPrinter::PrintNoData(aMsgId);
rv.SuppressException();
return;
}
@ -86,7 +99,7 @@ void MMPrinter::PrintImpl(char const* aLocation, const nsAString& aMsg,
if (!srcString.init(cx, unevalObj)) return;
MOZ_LOG(MMPrinter::sMMLog, LogLevel::Verbose,
("%" PRIu64 " %s", msg_id, NS_ConvertUTF16toUTF8(srcString).get()));
("%" PRIu64 " %s", aMsgId, NS_ConvertUTF16toUTF8(srcString).get()));
}
} // namespace mozilla::dom

View file

@ -7,6 +7,7 @@
#ifndef MMPrinter_h
#define MMPrinter_h
#include "mozilla/Maybe.h"
#include "mozilla/dom/DOMTypes.h"
#include "nsString.h"
@ -17,24 +18,40 @@ class MMPrinter {
static void Print(char const* aLocation, const nsAString& aMsg,
ClonedMessageData const& aData) {
if (MOZ_UNLIKELY(MOZ_LOG_TEST(MMPrinter::sMMLog, LogLevel::Debug))) {
MMPrinter::PrintImpl(aLocation, aMsg, aData);
Maybe<uint64_t> msgId = MMPrinter::PrintHeader(aLocation, aMsg);
if (!msgId.isSome()) {
return;
}
MMPrinter::PrintData(*msgId, aData);
}
}
static void Print(char const* aLocation, const nsACString& aActorName,
const nsAString& aMessageName,
ClonedMessageData const& aData) {
const Maybe<ClonedMessageData>& aData) {
if (MOZ_UNLIKELY(MOZ_LOG_TEST(MMPrinter::sMMLog, LogLevel::Debug))) {
MMPrinter::PrintImpl(
Maybe<uint64_t> msgId = MMPrinter::PrintHeader(
aLocation,
NS_ConvertUTF8toUTF16(aActorName + " - "_ns) + aMessageName, aData);
NS_ConvertUTF8toUTF16(aActorName + " - "_ns) + aMessageName);
if (!msgId.isSome()) {
return;
}
if (aData.isSome()) {
MMPrinter::PrintData(*msgId, *aData);
} else {
MMPrinter::PrintNoData(*msgId);
}
}
}
private:
static LazyLogModule sMMLog;
static void PrintImpl(char const* aLocation, const nsAString& aMsg,
ClonedMessageData const& aData);
static Maybe<uint64_t> PrintHeader(char const* aLocation,
const nsAString& aMsg);
static void PrintNoData(uint64_t aMsgId);
static void PrintData(uint64_t aMsgId, ClonedMessageData const& aData);
};
} // namespace mozilla::dom

View file

@ -566,7 +566,7 @@ IPCResult WindowGlobalParent::RecvRawMessage(
stack->BorrowFromClonedMessageData(*aStack);
}
MMPrinter::Print("WindowGlobalParent::RecvRawMessage", aMeta.actorName(),
aMeta.messageName(), *aData);
aMeta.messageName(), aData);
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
return IPC_OK();
}