Speculating on how the buggy control panel extension truncated a value that it had right in front of it - The Old New Thing
12 hours ago
- A crash in a control panel extension was caused by pointer truncation: the top 32 bits of a 64-bit pointer were discarded.
- The original 32-bit code used `SetWindowLong` with `GWL_WNDPROC` and a `(LONG)` cast, which worked in 32-bit mode.
- When recompiling for 64-bit, the build error prompted renaming `GWL_` to `GWLP_` to flag potential pointer truncation.
- The developer fixed the symbol name but neglected to update the cast from `(LONG)` to `(LONG_PTR)`, causing the truncation bug.
- The bug was likely an oversight; the developer had correctly subclassed the window elsewhere but missed this spot.
- The code likely dates from when 32-bit was common (15–20 years ago), and `SetWindowLongPtr` already existed but wasn't used.
- The proper fix is to use `SetWindowLongPtr` with `LONG_PTR` to handle pointers correctly on 64-bit systems.