-
Notifications
You must be signed in to change notification settings - Fork 498
Description
The alignment calculation formula (cb + 15) & ~0x7 unnecessarily adds 8 bytes when cb is already a multiple of 8.
Steps to Reproduce
Input: cb = 0x40 (64 bytes, already 8-byte aligned)
Expected: pMEM->cb = 0x40
Actual: pMEM->cb = 0x48 (72 bytes)
Impact
Memory waste: Wastes 8 bytes per alignment operation
May trigger unnecessary page boundary adjustments
Significant overhead when accumulated in loops
Suggested Fix
// Current:
pMEM->cb = (cb + 15) & ~0x7;
// Suggested:
pMEM->cb = (cb + 7) & ~0x7; // Standard round-up to 8-byte boundary
Additional Context
This appears to be a bug in the alignment calculation. The standard formula for rounding up to an 8-byte boundary is (cb + 7) & ~0x7. The current formula adds an extra 8 bytes even when the value is already properly aligned.