-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Open
Labels
Description
Describe the bug
Ghidra will erroneously convert the expression x <= SIGNED_INT_N_MAX to x < SIGNED_INT_N_MIN.
To Reproduce
Compile the following program (x64/linux) with clang -O0 test.c -o test
#include <stdlib.h>
int main(int argc, char** argv) {
int c = atoi(argv[1]);
if (c > 0x7fffffff) {
return 2;
}
return 4;
}Decompile the program in Ghidra, the output is the following:
undefined4 main(undefined8 param_1,long param_2)
{
int iVar1;
undefined4 local_c;
iVar1 = atoi(*(char **)(param_2 + 8));
if (iVar1 < -0x80000000) {
local_c = 4;
}
else {
local_c = 2;
}
return local_c;
}Importantly, the initial program always returns 4, whereas the decompiled code always returns 2.
Expected behavior
I would expect the condition to be iVar1 <= 0x7fffffff. Optionally, Ghidra may also completely optimize the condition out as it will always evaluate to the same value.
Environment (please complete the following information):
- OS: Arch Linux
- Java Version: openjdk 21.0.9 2025-10-21
- Ghidra Version: 11.4.2
- Ghidra Origin: official GitHub distro
AraCoders