mirror of https://github.com/mgba-emu/mgba.git
GBA BIOS: Fix INT_MIN/-1 crash
This commit is contained in:
parent
5fd8ebbbaf
commit
b97c871e1b
|
@ -256,18 +256,23 @@ static void _MidiKey2Freq(struct GBA* gba) {
|
||||||
|
|
||||||
static void _Div(struct GBA* gba, int32_t num, int32_t denom) {
|
static void _Div(struct GBA* gba, int32_t num, int32_t denom) {
|
||||||
struct ARMCore* cpu = gba->cpu;
|
struct ARMCore* cpu = gba->cpu;
|
||||||
if (denom != 0) {
|
if (denom != 0 && (denom != -1 || num != INT32_MIN)) {
|
||||||
div_t result = div(num, denom);
|
div_t result = div(num, denom);
|
||||||
cpu->gprs[0] = result.quot;
|
cpu->gprs[0] = result.quot;
|
||||||
cpu->gprs[1] = result.rem;
|
cpu->gprs[1] = result.rem;
|
||||||
cpu->gprs[3] = abs(result.quot);
|
cpu->gprs[3] = abs(result.quot);
|
||||||
} else {
|
} else if (denom == 0) {
|
||||||
mLOG(GBA_BIOS, GAME_ERROR, "Attempting to divide %i by zero!", num);
|
mLOG(GBA_BIOS, GAME_ERROR, "Attempting to divide %i by zero!", num);
|
||||||
// If abs(num) > 1, this should hang, but that would be painful to
|
// If abs(num) > 1, this should hang, but that would be painful to
|
||||||
// emulate in HLE, and no game will get into a state where it hangs...
|
// emulate in HLE, and no game will get into a state where it hangs...
|
||||||
cpu->gprs[0] = (num < 0) ? -1 : 1;
|
cpu->gprs[0] = (num < 0) ? -1 : 1;
|
||||||
cpu->gprs[1] = num;
|
cpu->gprs[1] = num;
|
||||||
cpu->gprs[3] = 1;
|
cpu->gprs[3] = 1;
|
||||||
|
} else {
|
||||||
|
mLOG(GBA_BIOS, GAME_ERROR, "Attempting to divide INT_MIN by -1!");
|
||||||
|
cpu->gprs[0] = INT32_MIN;
|
||||||
|
cpu->gprs[1] = 0;
|
||||||
|
cpu->gprs[3] = INT32_MIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue