oleaut32: Fixed bounds of VarIntFromFloat.

This commit is contained in:
Shuai Meng 2014-03-24 22:56:34 +08:00 committed by Alexandre Julliard
parent c820bddd74
commit 1809f7c782
2 changed files with 48 additions and 6 deletions

View File

@ -739,11 +739,15 @@ static void test_VarI1FromR4(void)
CHECKPTR(VarI1FromR4);
CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
CONVERT(VarI1FromR4, -128.51f); EXPECT_OVERFLOW;
CONVERT(VarI1FromR4, -128.5f); EXPECT(-128);
CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
CONVERT(VarI1FromR4, 127.49f); EXPECT(127);
CONVERT(VarI1FromR4, 127.5f); EXPECT_OVERFLOW;
CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
@ -762,11 +766,15 @@ static void test_VarI1FromR8(void)
CHECKPTR(VarI1FromR8);
CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
CONVERT(VarI1FromR8, -128.51); EXPECT_OVERFLOW;
CONVERT(VarI1FromR8, -128.5); EXPECT(-128);
CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
CONVERT(VarI1FromR8, 0.0); EXPECT(0);
CONVERT(VarI1FromR8, 1.0); EXPECT(1);
CONVERT(VarI1FromR8, 127.0); EXPECT(127);
CONVERT(VarI1FromR8, 127.49); EXPECT(127);
CONVERT(VarI1FromR8, 127.5); EXPECT_OVERFLOW;
CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
@ -983,9 +991,13 @@ static void test_VarUI1FromR4(void)
CHECKPTR(VarUI1FromR4);
CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR4, -0.51f); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
CONVERT(VarUI1FromR4, 255.49f); EXPECT(255);
CONVERT(VarUI1FromR4, 255.5f); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
/* Rounding */
@ -1005,9 +1017,13 @@ static void test_VarUI1FromR8(void)
CHECKPTR(VarUI1FromR8);
CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR8, -0.51); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
CONVERT(VarUI1FromR8, 255.49); EXPECT(255);
CONVERT(VarUI1FromR8, 255.5); EXPECT_OVERFLOW;
CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
/* Rounding */
@ -1281,11 +1297,15 @@ static void test_VarI2FromR4(void)
CHECKPTR(VarI2FromR4);
CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
CONVERT(VarI2FromR4, -32768.51f); EXPECT_OVERFLOW;
CONVERT(VarI2FromR4, -32768.5f); EXPECT(-32768);
CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
CONVERT(VarI2FromR4, 32767.49f); EXPECT(32767);
CONVERT(VarI2FromR4, 32767.5f); EXPECT_OVERFLOW;
CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
/* Rounding */
@ -1305,11 +1325,15 @@ static void test_VarI2FromR8(void)
CHECKPTR(VarI2FromR8);
CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
CONVERT(VarI2FromR8, -32768.51); EXPECT_OVERFLOW;
CONVERT(VarI2FromR8, -32768.5); EXPECT(-32768);
CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
CONVERT(VarI2FromR8, 0.0); EXPECT(0);
CONVERT(VarI2FromR8, 1.0); EXPECT(1);
CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
CONVERT(VarI2FromR8, 32767.49); EXPECT(32767);
CONVERT(VarI2FromR8, 32767.5); EXPECT_OVERFLOW;
CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
/* Rounding */
@ -1529,9 +1553,13 @@ static void test_VarUI2FromR4(void)
CHECKPTR(VarUI2FromR4);
CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR4, -0.51f); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
CONVERT(VarUI2FromR4, 65535.49f); EXPECT(65535);
CONVERT(VarUI2FromR4, 65535.5f); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
/* Rounding */
@ -1551,9 +1579,13 @@ static void test_VarUI2FromR8(void)
CHECKPTR(VarUI2FromR8);
CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR8, -0.51); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
CONVERT(VarUI2FromR8, 65535.49); EXPECT(65535);
CONVERT(VarUI2FromR8, 65535.5); EXPECT_OVERFLOW;
CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
/* Rounding */
@ -1792,11 +1824,15 @@ static void test_VarI4FromR8(void)
CHECKPTR(VarI4FromR8);
CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
CONVERT(VarI4FromR8, -2147483648.51); EXPECT_OVERFLOW;
CONVERT(VarI4FromR8, -2147483648.5); EXPECT(-2147483647 - 1);
CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
CONVERT(VarI4FromR8, 0.0); EXPECT(0);
CONVERT(VarI4FromR8, 1.0); EXPECT(1);
CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
CONVERT(VarI4FromR8, 2147483647.49); EXPECT(2147483647);
CONVERT(VarI4FromR8, 2147483647.5); EXPECT_OVERFLOW;
CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
@ -2017,6 +2053,8 @@ static void test_VarUI4FromR4(void)
CHECKPTR(VarUI4FromR4);
/* We can't test max values as they are not exactly representable in a float */
CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
@ -2037,9 +2075,13 @@ static void test_VarUI4FromR8(void)
CHECKPTR(VarUI4FromR8);
CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
CONVERT(VarUI4FromR8, 4294967295.49); EXPECT(4294967295ul);
CONVERT(VarUI4FromR8, 4294967295.5); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;

View File

@ -362,7 +362,7 @@ HRESULT WINAPI VarI1FromR4(FLOAT fltIn, signed char* pcOut)
*/
HRESULT WINAPI VarI1FromR8(double dblIn, signed char* pcOut)
{
if (dblIn < (double)I1_MIN || dblIn > (double)I1_MAX)
if (dblIn < I1_MIN - 0.5 || dblIn >= I1_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(CHAR, dblIn, *pcOut);
return S_OK;
@ -652,7 +652,7 @@ HRESULT WINAPI VarUI1FromR4(FLOAT fltIn, BYTE* pbOut)
*/
HRESULT WINAPI VarUI1FromR8(double dblIn, BYTE* pbOut)
{
if (dblIn < -0.5 || dblIn > (double)UI1_MAX)
if (dblIn < -0.5 || dblIn >= UI1_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(BYTE, dblIn, *pbOut);
return S_OK;
@ -958,7 +958,7 @@ HRESULT WINAPI VarI2FromR4(FLOAT fltIn, SHORT* psOut)
*/
HRESULT WINAPI VarI2FromR8(double dblIn, SHORT* psOut)
{
if (dblIn < (double)I2_MIN || dblIn > (double)I2_MAX)
if (dblIn < I2_MIN - 0.5 || dblIn >= I2_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(SHORT, dblIn, *psOut);
return S_OK;
@ -1270,7 +1270,7 @@ HRESULT WINAPI VarUI2FromR4(FLOAT fltIn, USHORT* pusOut)
*/
HRESULT WINAPI VarUI2FromR8(double dblIn, USHORT* pusOut)
{
if (dblIn < -0.5 || dblIn > (double)UI2_MAX)
if (dblIn < -0.5 || dblIn >= UI2_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(USHORT, dblIn, *pusOut);
return S_OK;
@ -1550,7 +1550,7 @@ HRESULT WINAPI VarI4FromR4(FLOAT fltIn, LONG *piOut)
*/
HRESULT WINAPI VarI4FromR8(double dblIn, LONG *piOut)
{
if (dblIn < (double)I4_MIN || dblIn > (double)I4_MAX)
if (dblIn < I4_MIN - 0.5 || dblIn >= I4_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(LONG, dblIn, *piOut);
return S_OK;
@ -1859,7 +1859,7 @@ HRESULT WINAPI VarUI4FromR4(FLOAT fltIn, ULONG *pulOut)
*/
HRESULT WINAPI VarUI4FromR8(double dblIn, ULONG *pulOut)
{
if (dblIn < -0.5 || dblIn > (double)UI4_MAX)
if (dblIn < -0.5 || dblIn >= UI4_MAX + 0.5)
return DISP_E_OVERFLOW;
VARIANT_DutchRound(ULONG, dblIn, *pulOut);
return S_OK;