Author: tfaber
Date: Sun Jul 26 07:48:24 2015
New Revision: 68572
URL:
http://svn.reactos.org/svn/reactos?rev=68572&view=rev
Log:
[PSDK]
- intsafe: use the correct type to check overflow in DEFINE_SAFE_ADD
CORE-9946 #resolve
Modified:
trunk/reactos/include/psdk/intsafe.h
trunk/rostests/kmtests/rtl/RtlIntSafe.c
Modified: trunk/reactos/include/psdk/intsafe.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/intsafe.h?rev…
==============================================================================
--- trunk/reactos/include/psdk/intsafe.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/intsafe.h [iso-8859-1] Sun Jul 26 07:48:24 2015
@@ -526,7 +526,7 @@
_In_ _Type Addend, \
_Out_ _Deref_out_range_(==, Augend + Addend) _Type *pOutput) \
{ \
- if ((Augend + Addend) >= Augend) \
+ if ((_Type)(Augend + Addend) >= Augend) \
{ \
*pOutput = Augend + Addend; \
return INTSAFE_SUCCESS; \
Modified: trunk/rostests/kmtests/rtl/RtlIntSafe.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/rtl/RtlIntSafe.c?…
==============================================================================
--- trunk/rostests/kmtests/rtl/RtlIntSafe.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/rtl/RtlIntSafe.c [iso-8859-1] Sun Jul 26 07:48:24 2015
@@ -95,4 +95,20 @@
TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN, SHORT_MIN,
STATUS_SUCCESS);
TEST_CONVERSION(Int, INT, Short, SHORT, int, SHORT_MIN - 1, (SHORT)-1,
STATUS_INTEGER_OVERFLOW);
TEST_CONVERSION(Int, INT, Short, SHORT, int, INT_MIN, (SHORT)-1,
STATUS_INTEGER_OVERFLOW);
+
+#define TEST_ADD(_Name, _Type, _Print, _Value1, _Value2, _Expected, _Status) do \
+ { \
+ _Name ## Result = (_Type)0xfedcba9876543210; \
+ Status = Rtl ## _Name ## Add(_Value1, _Value2, & _Name ## Result); \
+ ok_eq_hex(Status, _Status); \
+ ok_eq_ ## _Print(_Name ## Result, _Expected); \
+ } while (0)
+
+ TEST_ADD(UInt8, UINT8, uint, 0, 0, 0,
STATUS_SUCCESS);
+ TEST_ADD(UInt8, UINT8, uint, 5, 5, 10,
STATUS_SUCCESS);
+ TEST_ADD(UInt8, UINT8, uint, 0, UINT8_MAX,
UINT8_MAX, STATUS_SUCCESS);
+ TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, 0,
UINT8_MAX, STATUS_SUCCESS);
+ TEST_ADD(UInt8, UINT8, uint, UINT8_MAX - 1, 1,
UINT8_MAX, STATUS_SUCCESS);
+ TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, 1,
(UINT8)-1, STATUS_INTEGER_OVERFLOW);
+ TEST_ADD(UInt8, UINT8, uint, UINT8_MAX, UINT8_MAX,
(UINT8)-1, STATUS_INTEGER_OVERFLOW);
}