Rizin
unix-like reverse engineering framework and cli tools
rz_types_overflow.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Macros

#define SZT_ADD_OVFCHK(x, y)   ((SIZE_MAX - (x)) < (y))
 
#define SSZT_ADD_OVFCHK(a, x)   ((((x) > 0) && ((a) > SSIZE_MAX - (x))) || (((x) < 0) && (a) < SSIZE_MIN - (x)))
 
#define UT64_ADD_OVFCHK(x, y)   ((UT64_MAX - (x)) < (y))
 
#define ST64_ADD_OVFCHK(a, x)   ((((x) > 0) && ((a) > ST64_MAX - (x))) || (((x) < 0) && (a) < ST64_MIN - (x)))
 
#define UT32_ADD_OVFCHK(x, y)   ((UT32_MAX - (x)) < (y))
 
#define ST32_ADD_OVFCHK(a, x)   ((((x) > 0) && ((a) > ST32_MAX - (x))) || (((x) < 0) && (a) < ST32_MIN - (x)))
 
#define UT16_ADD_OVFCHK(x, y)   ((UT16_MAX - (x)) < (y))
 
#define ST16_ADD_OVFCHK(a, b)   ((((b) > 0) && ((a) > ST16_MAX - (b))) || (((b) < 0) && ((a) < ST16_MIN - (b))))
 
#define UT8_ADD_OVFCHK(x, y)   ((UT8_MAX - (x)) < (y))
 
#define ST8_ADD_OVFCHK(a, x)   ((((x) > 0) && ((a) > ST8_MAX - (x))) || ((x) < 0 && (a) < ST8_MIN - (x)))
 
#define SZT_SUB_OVFCHK(a, b)   SZT_ADD_OVFCHK(a, -(b))
 
#define SSZT_SUB_OVFCHK(a, b)   SSZT_ADD_OVFCHK(a, -(b))
 
#define UT64_SUB_OVFCHK(a, b)   UT64_ADD_OVFCHK(a, -(b))
 
#define ST64_SUB_OVFCHK(a, b)   ST64_ADD_OVFCHK(a, -(b))
 
#define UT32_SUB_OVFCHK(a, b)   UT32_ADD_OVFCHK(a, -(b))
 
#define ST32_SUB_OVFCHK(a, b)   ST32_ADD_OVFCHK(a, -(b))
 
#define UT16_SUB_OVFCHK(a, b)   UT16_ADD_OVFCHK(a, -(b))
 
#define ST16_SUB_OVFCHK(a, b)   ST16_ADD_OVFCHK(a, -(b))
 
#define UT8_SUB_OVFCHK(a, b)   UT8_ADD_OVFCHK(a, -(b))
 
#define ST8_SUB_OVFCHK(a, b)   ST8_ADD_OVFCHK(a, -(b))
 
#define UNSIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
 
#define SIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
 
#define SIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_mid, type_max)
 
#define UNSIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
 

Macro Definition Documentation

◆ SIGNED_DIV_OVERFLOW_CHECK

#define SIGNED_DIV_OVERFLOW_CHECK (   overflow_name,
  type_base,
  type_mid,
  type_max 
)
Value:
static inline bool overflow_name(type_base a, type_base b) { \
return (!b || (a == type_mid && b == type_max)); \
}
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

Definition at line 56 of file rz_types_overflow.h.

◆ SIGNED_MUL_OVERFLOW_CHECK

#define SIGNED_MUL_OVERFLOW_CHECK (   overflow_name,
  type_base,
  type_min,
  type_max 
)
Value:
static inline bool overflow_name(type_base a, type_base b) { \
if (a > 0) { \
if (b > 0) { \
return a > type_max / b; \
} \
return b < type_min / a; \
} \
if (b > 0) { \
return a < type_min / b; \
} \
return a && b < type_max / a; \
}

Definition at line 42 of file rz_types_overflow.h.

◆ SSZT_ADD_OVFCHK

#define SSZT_ADD_OVFCHK (   a,
  x 
)    ((((x) > 0) && ((a) > SSIZE_MAX - (x))) || (((x) < 0) && (a) < SSIZE_MIN - (x)))

Definition at line 12 of file rz_types_overflow.h.

◆ SSZT_SUB_OVFCHK

#define SSZT_SUB_OVFCHK (   a,
  b 
)    SSZT_ADD_OVFCHK(a, -(b))

Definition at line 26 of file rz_types_overflow.h.

◆ ST16_ADD_OVFCHK

#define ST16_ADD_OVFCHK (   a,
  b 
)    ((((b) > 0) && ((a) > ST16_MAX - (b))) || (((b) < 0) && ((a) < ST16_MIN - (b))))

Definition at line 18 of file rz_types_overflow.h.

◆ ST16_SUB_OVFCHK

#define ST16_SUB_OVFCHK (   a,
  b 
)    ST16_ADD_OVFCHK(a, -(b))

Definition at line 32 of file rz_types_overflow.h.

◆ ST32_ADD_OVFCHK

#define ST32_ADD_OVFCHK (   a,
  x 
)    ((((x) > 0) && ((a) > ST32_MAX - (x))) || (((x) < 0) && (a) < ST32_MIN - (x)))

Definition at line 16 of file rz_types_overflow.h.

◆ ST32_SUB_OVFCHK

#define ST32_SUB_OVFCHK (   a,
  b 
)    ST32_ADD_OVFCHK(a, -(b))

Definition at line 30 of file rz_types_overflow.h.

◆ ST64_ADD_OVFCHK

#define ST64_ADD_OVFCHK (   a,
  x 
)    ((((x) > 0) && ((a) > ST64_MAX - (x))) || (((x) < 0) && (a) < ST64_MIN - (x)))

Definition at line 14 of file rz_types_overflow.h.

◆ ST64_SUB_OVFCHK

#define ST64_SUB_OVFCHK (   a,
  b 
)    ST64_ADD_OVFCHK(a, -(b))

Definition at line 28 of file rz_types_overflow.h.

◆ ST8_ADD_OVFCHK

#define ST8_ADD_OVFCHK (   a,
  x 
)    ((((x) > 0) && ((a) > ST8_MAX - (x))) || ((x) < 0 && (a) < ST8_MIN - (x)))

Definition at line 20 of file rz_types_overflow.h.

◆ ST8_SUB_OVFCHK

#define ST8_SUB_OVFCHK (   a,
  b 
)    ST8_ADD_OVFCHK(a, -(b))

Definition at line 34 of file rz_types_overflow.h.

◆ SZT_ADD_OVFCHK

#define SZT_ADD_OVFCHK (   x,
 
)    ((SIZE_MAX - (x)) < (y))

Definition at line 11 of file rz_types_overflow.h.

◆ SZT_SUB_OVFCHK

#define SZT_SUB_OVFCHK (   a,
  b 
)    SZT_ADD_OVFCHK(a, -(b))

Definition at line 25 of file rz_types_overflow.h.

◆ UNSIGNED_DIV_OVERFLOW_CHECK

#define UNSIGNED_DIV_OVERFLOW_CHECK (   overflow_name,
  type_base,
  type_min,
  type_max 
)
Value:
static inline bool overflow_name(type_base a, type_base b) { \
(void)a; \
return !b; \
}

Definition at line 60 of file rz_types_overflow.h.

◆ UNSIGNED_MUL_OVERFLOW_CHECK

#define UNSIGNED_MUL_OVERFLOW_CHECK (   overflow_name,
  type_base,
  type_min,
  type_max 
)
Value:
static inline bool overflow_name(type_base a, type_base b) { \
return (a > 0 && b > 0 && a > type_max / b); \
}

Definition at line 37 of file rz_types_overflow.h.

◆ UT16_ADD_OVFCHK

#define UT16_ADD_OVFCHK (   x,
 
)    ((UT16_MAX - (x)) < (y))

Definition at line 17 of file rz_types_overflow.h.

◆ UT16_SUB_OVFCHK

#define UT16_SUB_OVFCHK (   a,
  b 
)    UT16_ADD_OVFCHK(a, -(b))

Definition at line 31 of file rz_types_overflow.h.

◆ UT32_ADD_OVFCHK

#define UT32_ADD_OVFCHK (   x,
 
)    ((UT32_MAX - (x)) < (y))

Definition at line 15 of file rz_types_overflow.h.

◆ UT32_SUB_OVFCHK

#define UT32_SUB_OVFCHK (   a,
  b 
)    UT32_ADD_OVFCHK(a, -(b))

Definition at line 29 of file rz_types_overflow.h.

◆ UT64_ADD_OVFCHK

#define UT64_ADD_OVFCHK (   x,
 
)    ((UT64_MAX - (x)) < (y))

Definition at line 13 of file rz_types_overflow.h.

◆ UT64_SUB_OVFCHK

#define UT64_SUB_OVFCHK (   a,
  b 
)    UT64_ADD_OVFCHK(a, -(b))

Definition at line 27 of file rz_types_overflow.h.

◆ UT8_ADD_OVFCHK

#define UT8_ADD_OVFCHK (   x,
 
)    ((UT8_MAX - (x)) < (y))

Definition at line 19 of file rz_types_overflow.h.

◆ UT8_SUB_OVFCHK

#define UT8_SUB_OVFCHK (   a,
  b 
)    UT8_ADD_OVFCHK(a, -(b))

Definition at line 33 of file rz_types_overflow.h.