Skip to content

Commit 4fb9d42

Browse files
committed
Fix segfault in accrual age calculation
This fixes a segmentation fault caused by dereferencing a null pointer when attempting to calculate accrual age for a CPID with no beacon.
1 parent 5d360bb commit 4fb9d42

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/neuralnet/accrual/snapshot.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,15 @@ class SnapshotAccrualComputer : public IAccrualComputer, SnapshotCalculator
234234
// a superblock after contract improvements for more accurate age.
235235
//
236236
if (m_account.IsNew()) {
237-
const int64_t beacon_time = GetBeaconRegistry().Try(m_cpid)->m_timestamp;
237+
if (const BeaconOption beacon = GetBeaconRegistry().Try(m_cpid)) {
238+
const int64_t beacon_time = beacon->m_timestamp;
238239

239-
if (beacon_time <= 0) {
240-
return 0;
240+
if (beacon_time > 0) {
241+
return m_payment_time - beacon_time;
242+
}
241243
}
242244

243-
return m_payment_time - beacon_time;
245+
return 0;
244246
}
245247

246248
return SnapshotCalculator::AccrualAge(m_account);

0 commit comments

Comments
 (0)