[WIN32K] Fix getting long value from float object

Most importantly, do not shift 32-bit integers by 32 or more.
This commit is contained in:
Jérôme Gardou 2021-03-22 12:39:08 +01:00 committed by Jérôme Gardou
parent 405ce53211
commit 12dfa8ce39
4 changed files with 34 additions and 46 deletions

View file

@ -213,6 +213,7 @@ list(APPEND ASM_SOURCE
gdi/dib/i386/dib32bpp_hline.s
gdi/dib/i386/dib32bpp_colorfill.s
gdi/eng/i386/floatobj.S)
list(APPEND SOURCE gdi/eng/i386/floatobj.c)
else()
list(APPEND SOURCE
gdi/dib/dib24bppc.c

View file

@ -16,15 +16,6 @@ _FLOATOBJ_Equal(FLOATOBJ *pf1, FLOATOBJ *pf2)
}
#define FLOATOBJ_Equal _FLOATOBJ_Equal
FORCEINLINE
LONG
_FLOATOBJ_GetLong(FLOATOBJ *pf)
{
EFLOAT_S *pef = (EFLOAT_S*)pf;
return pef->lMant >> (32 - pef->lExp);
}
#define FLOATOBJ_GetLong _FLOATOBJ_GetLong
/*!
* \brief Converts a FLOATOBJ into a LONG by truncating the value to integer
*
@ -37,16 +28,22 @@ _FLOATOBJ_GetLong(FLOATOBJ *pf)
*/
FORCEINLINE
BOOL
FASTCALL
FLOATOBJ_bConvertToLong(FLOATOBJ *pf, PLONG pl)
{
EFLOAT_S *pef = (EFLOAT_S*)pf;
LONG lShift = 32 - pef->lExp;
if (lShift < 0)
if (pef->lExp > 32)
{
return FALSE;
}
*pl = pef->lMant >> lShift;
if (pef->lExp < 2)
{
*pl = 0;
return TRUE;
}
*pl = EngMulDiv(pef->lMant, 1 << (pef->lExp - 2), 0x40000000);
return TRUE;
}

View file

@ -52,7 +52,7 @@
* FLOATOBJ_SetFloat - implemented, tested
* FLOATOBJ_SetLong - implemented, tested
* FLOATOBJ_GetFloat - implemented, tested
* FLOATOBJ_GetLong - implemented, tested
* FLOATOBJ_GetLong - implemented in C
* FLOATOBJ_Equal - implemented, tested
* FLOATOBJ_EqualLong - implemented
* FLOATOBJ_GreaterThan - implemented
@ -249,34 +249,6 @@ SetLong0:
ret 8
/*******************************************************************************
* LONG
* APIENTRY
* FLOATOBJ_GetLong(IN PFLOATOBJ pf);
*
*/
_FLOATOBJ_GetLong@4:
PUBLIC _FLOATOBJ_GetLong@4
push ebp
mov ebp, esp
mov edx, [ebp + PARAM1] /* Load pf into edx */
mov ecx, 32 /* Load (32 - lExp) into ecx */
sub ecx, [edx + lExp]
jle short GetLong2 /* Check for Overflow */
mov eax, [edx + lMant] /* Load mantissa into eax */
sar eax, cl /* Signed shift mantissa according to exponent */
pop ebp /* Return */
ret 4
GetLong2:
xor eax, eax /* Overflow, return 0 */
pop ebp
ret 4
/******************************************************************************
* BOOL
* APIENTRY
@ -842,7 +814,6 @@ PUBLIC _FLOATOBJ_DivLong@8
pop ebp
ret 8
/*******************************************************************************
* VOID
* APIENTRY
@ -940,7 +911,6 @@ AddIs0:
pop ebp
ret 8
/******************************************************************************
* VOID
* APIENTRY
@ -998,7 +968,6 @@ PUBLIC _FLOATOBJ_AddLong@8
pop ebp
ret 8
/*******************************************************************************
* VOID
* APIENTRY
@ -1095,7 +1064,6 @@ SubIs0:
mov dword ptr [eax + lExp], 0
pop ebp
ret 8
/******************************************************************************
* VOID
* APIENTRY

View file

@ -0,0 +1,22 @@
/*
* PROJECT: ReactOS win32 kernel mode subsystem
* LICENSE: GPL - See COPYING in the top level directory
* FILE: win32ss/gdi/eng/i386/floatobj.c
* PURPOSE: FLOATOBJ API
* PROGRAMMERS: Jérôme Gardou
*/
/** Includes ******************************************************************/
#include <win32k.h>
#define NDEBUG
#include <debug.h>
LONG
APIENTRY
FLOATOBJ_GetLong(FLOATOBJ* pf)
{
LONG val = 0;
(void)FLOATOBJ_bConvertToLong(pf, &val);
return val;
}