`detour_sign_extend` is implemented incorrectly
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 6.4k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Currently, detour_sign_extend has the following implementation:
inline INT64 detour_sign_extend(UINT64 value, UINT bits)
{
const UINT left = 64 - bits;
const INT64 m1 = -1;
const INT64 wide = (INT64)(value << left);
const INT64 sign = (wide < 0) ? (m1 << left) : 0;
return value | sign;
}
But the sign computation is incorrect here. The result should be the following: left upper bits of sign and then bits lower bits of value. But m1 is shifted left by left bits in the current implementation, so we will use bits bits of the sign. It's an error.
The proper sign computation should be
const INT64 sign = (wide < 0) ? (m1 << bits) : 0;
As an example, you can consider the following case that I met:
valueis0xffea2e4,bitsis 28.- The expected result is
0xfffffffffffea2e4:64 - 28 = 36upper bits of thesignand then28bits of thevalue. - The actual result of the current implementation is
0xfffffff00ffea2e4, that is obviously wrong.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the detour_sign_extend implementation shown in the issue and inspect how its sign mask is computed. Update the incorrect shift as specified, then verify the provided value 0xffea2e4 with bits set to 28 produces 0xfffffffffffea2e4.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100