Add null check to DebugTracePlayer.

Navigating away from the Debugger in Viewer could lead to a null
dereference.

Change-Id: I2686edd3716e7a375d394a4dc1a296395b5f35b8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/514579
Reviewed-by: Arman Uguray <armansito@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-03-03 15:14:17 -05:00 committed by SkCQ
parent c8e520e722
commit ae8d412b9a
2 changed files with 22 additions and 7 deletions

View File

@ -25,15 +25,17 @@ void SkVMDebugTracePlayer::reset(sk_sp<SkVMDebugTrace> debugTrace) {
fDirtyMask.emplace(nslots);
fReturnValues.emplace(nslots);
for (size_t slotIdx = 0; slotIdx < nslots; ++slotIdx) {
if (fDebugTrace->fSlotInfo[slotIdx].fnReturnValue >= 0) {
fReturnValues->set(slotIdx);
if (fDebugTrace) {
for (size_t slotIdx = 0; slotIdx < nslots; ++slotIdx) {
if (fDebugTrace->fSlotInfo[slotIdx].fnReturnValue >= 0) {
fReturnValues->set(slotIdx);
}
}
}
for (const SkVMTraceInfo& trace : fDebugTrace->fTraceInfo) {
if (trace.op == SkVMTraceInfo::Op::kLine) {
fLineNumbers[trace.data[0]] += 1;
for (const SkVMTraceInfo& trace : fDebugTrace->fTraceInfo) {
if (trace.op == SkVMTraceInfo::Op::kLine) {
fLineNumbers[trace.data[0]] += 1;
}
}
}
}

View File

@ -93,6 +93,19 @@ static std::string make_global_vars_string(const SkSL::SkVMDebugTrace& trace,
return make_vars_string(trace, player.getGlobalVariables());
}
DEF_TEST(SkSLTracePlayerCanResetToNull, r) {
SkSL::SkVMDebugTracePlayer player;
player.reset(nullptr);
// We should be in a reasonable state.
REPORTER_ASSERT(r, player.cursor() == 0);
REPORTER_ASSERT(r, player.getCurrentLine() == -1);
REPORTER_ASSERT(r, player.traceHasCompleted());
REPORTER_ASSERT(r, player.getCallStack().empty());
REPORTER_ASSERT(r, player.getGlobalVariables().empty());
REPORTER_ASSERT(r, player.getLineNumbersReached().empty());
}
DEF_TEST(SkSLTracePlayerHelloWorld, r) {
sk_sp<SkSL::SkVMDebugTrace> trace = make_trace(r,
R"( // Line 1