Skip to content

Commit 792e824

Browse files
xusheng6claude
andauthored
Fix #994: Values wider than 8 bytes show as 0x0 in TTD memory widget (#996)
The original display code had undefined behavior when event.size > 8: `1ULL << (event.size * 8)` with size=16 shifts by 128 bits, which is undefined behavior in C++. On many platforms this wraps to shift by 0, making the mask 0, causing the value to display as 0x0. TTD always returns 8 bytes in the Value field regardless of access size, so we need to mask to show the correct number of bytes. The fix: - For sizes < 8: Apply the mask (safe, shift is < 64 bits) - For sizes >= 8: Display the full 8-byte value (avoids UB) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cf9ae88 commit 792e824

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

ui/ttdmemorywidget.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,20 @@ void TTDMemoryQueryWidget::performQuery()
436436

437437
// Size
438438
m_resultsTable->setItem(i, 4, new NumericalTableWidgetItem(QString::number(event.size), event.size));
439-
440-
// Value truncated to the number of bytes specified by size
441-
QString valueStr = QString("0x%1").arg(event.value & ((1ULL << (event.size * 8)) - 1), 0, 16);
439+
440+
// Value - TTD always returns 8 bytes, so mask to the actual access size
441+
// Note: For sizes > 8 bytes, TTD only provides the lower 8 bytes in the Value field
442+
QString valueStr;
443+
if (event.size < 8)
444+
{
445+
uint64_t mask = (1ULL << (event.size * 8)) - 1;
446+
valueStr = QString("0x%1").arg(event.value & mask, 0, 16);
447+
}
448+
else
449+
{
450+
// For sizes >= 8, display the full 8-byte value
451+
valueStr = QString("0x%1").arg(event.value, 0, 16);
452+
}
442453
m_resultsTable->setItem(i, 5, new NumericalTableWidgetItem(valueStr, event.value));
443454

444455
// Thread ID

0 commit comments

Comments
 (0)