From 3bdb6b6e457d23230f8fa8b1f2281b8d2a1692ee Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Mon, 18 May 2015 23:33:25 +0000 Subject: [PATCH] [FAST486] Add checks for special numbers in Fast486FpuAdd. Don't use pointers to out-of-scope variables. svn path=/trunk/; revision=67826 --- reactos/lib/fast486/fpu.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/reactos/lib/fast486/fpu.c b/reactos/lib/fast486/fpu.c index 3f2d2a7ccd0..f84a926503d 100644 --- a/reactos/lib/fast486/fpu.c +++ b/reactos/lib/fast486/fpu.c @@ -591,6 +591,18 @@ Fast486FpuAdd(PFAST486_STATE State, FAST486_FPU_DATA_REG SecondAdjusted = *SecondOperand; FAST486_FPU_DATA_REG TempResult; + if (FPU_IS_INDEFINITE(FirstOperand) + || FPU_IS_INDEFINITE(SecondOperand) + || (FPU_IS_POS_INF(FirstOperand) && FPU_IS_NEG_INF(SecondOperand)) + || (FPU_IS_NEG_INF(FirstOperand) && FPU_IS_POS_INF(SecondOperand))) + { + /* The result will be indefinite */ + Result->Sign = TRUE; + Result->Exponent = FPU_MAX_EXPONENT + 1; + Result->Mantissa = FPU_INDEFINITE_MANTISSA; + return TRUE; + } + if ((!FPU_IS_NORMALIZED(FirstOperand) || !FPU_IS_NORMALIZED(SecondOperand))) { /* Raise the denormalized exception */ @@ -603,6 +615,20 @@ Fast486FpuAdd(PFAST486_STATE State, } } + if (FPU_IS_ZERO(FirstOperand) || FPU_IS_INFINITY(SecondOperand)) + { + /* The second operand is the result */ + *Result = *SecondOperand; + return TRUE; + } + + if (FPU_IS_ZERO(SecondOperand) || FPU_IS_INFINITY(FirstOperand)) + { + /* The first operand is the result */ + *Result = *FirstOperand; + return TRUE; + } + /* Find the largest exponent */ TempResult.Exponent = max(FirstOperand->Exponent, SecondOperand->Exponent); @@ -2942,6 +2968,7 @@ FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE) BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size; #ifndef FAST486_NO_FPU PFAST486_FPU_DATA_REG SourceOperand, DestOperand; + FAST486_FPU_DATA_REG MemoryData; #endif TOGGLE_ADSIZE(AddressSize); @@ -2962,7 +2989,6 @@ FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE) if (ModRegRm.Memory) { SHORT Value; - FAST486_FPU_DATA_REG MemoryData; /* The destination operand is ST0 */ DestOperand = &FPU_ST(0);