49 int64_t widened = (int64_t)in;
64 int64_t widened = (int64_t)in;
79 int64_t widened = (int64_t)in;
94 int64_t widened = (int64_t)in;
109 int64_t widened = (int64_t)in;
114#if SIZE_MAX < UINT64_MAX
115 if ((uint64_t)widened > (uint64_t)SIZE_MAX)
130 int64_t widened = (int64_t)in;
131 if (widened < (int64_t)INT8_MIN)
135 if (widened > (int64_t)INT8_MAX)
169 int64_t widened = (int64_t)in;
174 if ((uint64_t)widened > (uint64_t)UINT8_MAX)
188 int64_t widened = (int64_t)in;
203 int64_t widened = (int64_t)in;
218 int64_t widened = (int64_t)in;
233 int64_t widened = (int64_t)in;
238#if SIZE_MAX < UINT64_MAX
239 if ((uint64_t)widened > (uint64_t)SIZE_MAX)
254 int64_t widened = (int64_t)in;
255 if (widened < (int64_t)INT8_MIN)
259 if (widened > (int64_t)INT8_MAX)
273 int64_t widened = (int64_t)in;
274 if (widened < (int64_t)INT16_MIN)
278 if (widened > (int64_t)INT16_MAX)
302 int64_t widened = (int64_t)in;
307 if ((uint64_t)widened > (uint64_t)UINT8_MAX)
321 int64_t widened = (int64_t)in;
326 if ((uint64_t)widened > (uint64_t)UINT16_MAX)
340 int64_t widened = (int64_t)in;
355 int64_t widened = (int64_t)in;
370 int64_t widened = (int64_t)in;
375#if SIZE_MAX < UINT64_MAX
376 if ((uint64_t)widened > (uint64_t)SIZE_MAX)
391 int64_t widened = (int64_t)in;
392 if (widened < (int64_t)INT8_MIN)
396 if (widened > (int64_t)INT8_MAX)
410 int64_t widened = (int64_t)in;
411 if (widened < (int64_t)INT16_MIN)
415 if (widened > (int64_t)INT16_MAX)
429 int64_t widened = (int64_t)in;
430 if (widened < (int64_t)INT32_MIN)
434 if (widened > (int64_t)INT32_MAX)
448 int64_t widened = (int64_t)in;
453 if ((uint64_t)widened > (uint64_t)UINT8_MAX)
467 int64_t widened = (int64_t)in;
472 if ((uint64_t)widened > (uint64_t)UINT16_MAX)
486 int64_t widened = (int64_t)in;
491 if ((uint64_t)widened > (uint64_t)UINT32_MAX)
505 int64_t widened = (int64_t)in;
520 int64_t widened = (int64_t)in;
525#if SIZE_MAX < UINT64_MAX
526 if ((uint64_t)widened > (uint64_t)SIZE_MAX)
541 uint64_t widened = (uint64_t)in;
542 if (widened > (uint64_t)INT8_MAX)
616#if SIZE_MAX < UINT64_MAX
618 uint64_t widened = (uint64_t)in;
619 if (widened > (uint64_t)SIZE_MAX)
635 uint64_t widened = (uint64_t)in;
636 if (widened > (uint64_t)INT8_MAX)
650 uint64_t widened = (uint64_t)in;
651 if (widened > (uint64_t)INT16_MAX)
685 uint64_t widened = (uint64_t)in;
686 if (widened > (uint64_t)UINT8_MAX)
720#if SIZE_MAX < UINT64_MAX
722 uint64_t widened = (uint64_t)in;
723 if (widened > (uint64_t)SIZE_MAX)
739 uint64_t widened = (uint64_t)in;
740 if (widened > (uint64_t)INT8_MAX)
754 uint64_t widened = (uint64_t)in;
755 if (widened > (uint64_t)INT16_MAX)
769 uint64_t widened = (uint64_t)in;
770 if (widened > (uint64_t)INT32_MAX)
794 uint64_t widened = (uint64_t)in;
795 if (widened > (uint64_t)UINT8_MAX)
809 uint64_t widened = (uint64_t)in;
810 if (widened > (uint64_t)UINT16_MAX)
834#if SIZE_MAX < UINT64_MAX
836 uint64_t widened = (uint64_t)in;
837 if (widened > (uint64_t)SIZE_MAX)
853 uint64_t widened = (uint64_t)in;
854 if (widened > (uint64_t)INT8_MAX)
868 uint64_t widened = (uint64_t)in;
869 if (widened > (uint64_t)INT16_MAX)
883 uint64_t widened = (uint64_t)in;
884 if (widened > (uint64_t)INT32_MAX)
898 uint64_t widened = (uint64_t)in;
899 if (widened > (uint64_t)INT64_MAX)
913 uint64_t widened = (uint64_t)in;
914 if (widened > (uint64_t)UINT8_MAX)
928 uint64_t widened = (uint64_t)in;
929 if (widened > (uint64_t)UINT16_MAX)
943 uint64_t widened = (uint64_t)in;
944 if (widened > (uint64_t)UINT32_MAX)
958#if SIZE_MAX < UINT64_MAX
960 uint64_t widened = (uint64_t)in;
961 if (widened > (uint64_t)SIZE_MAX)
978 uint64_t widened = (uint64_t)in;
979 if (widened > (uint64_t)INT8_MAX)
994 uint64_t widened = (uint64_t)in;
995 if (widened > (uint64_t)INT16_MAX)
1010 uint64_t widened = (uint64_t)in;
1011 if (widened > (uint64_t)INT32_MAX)
1026 uint64_t widened = (uint64_t)in;
1027 if (widened > (uint64_t)INT64_MAX)
1042 uint64_t widened = (uint64_t)in;
1043 if (widened > (uint64_t)UINT8_MAX)
1058 uint64_t widened = (uint64_t)in;
1059 if (widened > (uint64_t)UINT16_MAX)
1063 *out = (uint16_t)in;
1074 uint64_t widened = (uint64_t)in;
1075 if (widened > (uint64_t)UINT32_MAX)
1079 *out = (uint32_t)in;
1090 *out = (uint64_t)in;
1104 uint64_t widened = (uint64_t)a + (uint64_t)b;
1105 if (widened > (uint64_t)UINT32_MAX)
1108 "sapi_cast_checked_add_u32: addition overflowed uint32_t");
1111 *out = (uint32_t)widened;
1124 "sapi_cast_checked_sub_u32: subtraction underflowed uint32_t");
1137 uint64_t widened = (uint64_t)a * (uint64_t)b;
1138 if (widened > (uint64_t)UINT32_MAX)
1141 "sapi_cast_checked_mul_u32: multiplication overflowed uint32_t");
1144 *out = (uint32_t)widened;
1157 if (b > (SIZE_MAX - a))
1160 "sapi_cast_checked_add_size: addition overflowed size_t");
1176 "sapi_cast_checked_sub_size: subtraction underflowed size_t");
1189 if ((a != 0U) && (b > (SIZE_MAX / a)))
1192 "sapi_cast_checked_mul_size: multiplication overflowed size_t");
1204 "sapi_cast_bounds_check: index out of range");
sapi_status_t sapi_cast_u8_to_u32(uint8_t in, uint32_t *out)
Checked cast from uint8_t to uint32_t.
sapi_status_t sapi_cast_i16_to_u32(int16_t in, uint32_t *out)
Checked cast from int16_t to uint32_t.
sapi_status_t sapi_cast_i8_to_size(int8_t in, size_t *out)
Checked cast from int8_t to size_t.
sapi_status_t sapi_cast_u8_to_i8(uint8_t in, int8_t *out)
Checked cast from uint8_t to int8_t.
sapi_status_t sapi_cast_i16_to_size(int16_t in, size_t *out)
Checked cast from int16_t to size_t.
sapi_status_t sapi_cast_u32_to_size(uint32_t in, size_t *out)
Checked cast from uint32_t to size_t.
sapi_status_t sapi_cast_i16_to_u64(int16_t in, uint64_t *out)
Checked cast from int16_t to uint64_t.
sapi_status_t sapi_cast_u64_to_u8(uint64_t in, uint8_t *out)
Checked cast from uint64_t to uint8_t.
sapi_status_t sapi_cast_checked_sub_u32(uint32_t a, uint32_t b, uint32_t *out)
Checked subtraction: *out = a - b, only if b <= a (no underflow).
sapi_status_t sapi_cast_checked_mul_size(size_t a, size_t b, size_t *out)
Checked multiplication: *out = a * b, only if the result fits size_t.
sapi_status_t sapi_cast_size_to_u8(size_t in, uint8_t *out)
Checked cast from size_t to uint8_t.
sapi_status_t sapi_cast_u8_to_i32(uint8_t in, int32_t *out)
Checked cast from uint8_t to int32_t.
sapi_status_t sapi_cast_size_to_u32(size_t in, uint32_t *out)
Checked cast from size_t to uint32_t.
sapi_status_t sapi_cast_bounds_check(size_t index, size_t count)
Checked array/index bounds check: is index a valid index into an array of count elements?
sapi_status_t sapi_cast_size_to_i8(size_t in, int8_t *out)
Checked cast from size_t to int8_t.
sapi_status_t sapi_cast_i64_to_u32(int64_t in, uint32_t *out)
Checked cast from int64_t to uint32_t.
sapi_status_t sapi_cast_u32_to_i16(uint32_t in, int16_t *out)
Checked cast from uint32_t to int16_t.
sapi_status_t sapi_cast_u16_to_u64(uint16_t in, uint64_t *out)
Checked cast from uint16_t to uint64_t.
sapi_status_t sapi_cast_u8_to_size(uint8_t in, size_t *out)
Checked cast from uint8_t to size_t.
sapi_status_t sapi_cast_u64_to_i16(uint64_t in, int16_t *out)
Checked cast from uint64_t to int16_t.
sapi_status_t sapi_cast_i32_to_u16(int32_t in, uint16_t *out)
Checked cast from int32_t to uint16_t.
sapi_status_t sapi_cast_u8_to_u16(uint8_t in, uint16_t *out)
Checked cast from uint8_t to uint16_t.
sapi_status_t sapi_cast_u32_to_i64(uint32_t in, int64_t *out)
Checked cast from uint32_t to int64_t.
sapi_status_t sapi_cast_u16_to_size(uint16_t in, size_t *out)
Checked cast from uint16_t to size_t.
sapi_status_t sapi_cast_i16_to_i64(int16_t in, int64_t *out)
Checked cast from int16_t to int64_t.
sapi_status_t sapi_cast_u64_to_u16(uint64_t in, uint16_t *out)
Checked cast from uint64_t to uint16_t.
sapi_status_t sapi_cast_u8_to_i16(uint8_t in, int16_t *out)
Checked cast from uint8_t to int16_t.
sapi_status_t sapi_cast_i8_to_i32(int8_t in, int32_t *out)
Checked cast from int8_t to int32_t.
sapi_status_t sapi_cast_size_to_i16(size_t in, int16_t *out)
Checked cast from size_t to int16_t.
sapi_status_t sapi_cast_u64_to_i64(uint64_t in, int64_t *out)
Checked cast from uint64_t to int64_t.
sapi_status_t sapi_cast_i64_to_i16(int64_t in, int16_t *out)
Checked cast from int64_t to int16_t.
sapi_status_t sapi_cast_i8_to_i16(int8_t in, int16_t *out)
Checked cast from int8_t to int16_t.
sapi_status_t sapi_cast_i32_to_u8(int32_t in, uint8_t *out)
Checked cast from int32_t to uint8_t.
sapi_status_t sapi_cast_size_to_u16(size_t in, uint16_t *out)
Checked cast from size_t to uint16_t.
sapi_status_t sapi_cast_u8_to_u64(uint8_t in, uint64_t *out)
Checked cast from uint8_t to uint64_t.
sapi_status_t sapi_cast_u32_to_i8(uint32_t in, int8_t *out)
Checked cast from uint32_t to int8_t.
sapi_status_t sapi_cast_size_to_u64(size_t in, uint64_t *out)
Checked cast from size_t to uint64_t.
sapi_status_t sapi_cast_u16_to_u32(uint16_t in, uint32_t *out)
Checked cast from uint16_t to uint32_t.
sapi_status_t sapi_cast_i64_to_i8(int64_t in, int8_t *out)
Checked cast from int64_t to int8_t.
sapi_status_t sapi_cast_u64_to_size(uint64_t in, size_t *out)
Checked cast from uint64_t to size_t.
sapi_status_t sapi_cast_u16_to_i32(uint16_t in, int32_t *out)
Checked cast from uint16_t to int32_t.
sapi_status_t sapi_cast_u32_to_i32(uint32_t in, int32_t *out)
Checked cast from uint32_t to int32_t.
sapi_status_t sapi_cast_i8_to_u16(int8_t in, uint16_t *out)
Checked cast from int8_t to uint16_t.
sapi_status_t sapi_cast_u32_to_u8(uint32_t in, uint8_t *out)
Checked cast from uint32_t to uint8_t.
sapi_status_t sapi_cast_checked_add_size(size_t a, size_t b, size_t *out)
Checked addition: *out = a + b, only if the result fits size_t.
sapi_status_t sapi_cast_u16_to_i64(uint16_t in, int64_t *out)
Checked cast from uint16_t to int64_t.
sapi_status_t sapi_cast_i16_to_u16(int16_t in, uint16_t *out)
Checked cast from int16_t to uint16_t.
sapi_status_t sapi_cast_u16_to_u8(uint16_t in, uint8_t *out)
Checked cast from uint16_t to uint8_t.
sapi_status_t sapi_cast_u32_to_u16(uint32_t in, uint16_t *out)
Checked cast from uint32_t to uint16_t.
sapi_status_t sapi_cast_i64_to_u64(int64_t in, uint64_t *out)
Checked cast from int64_t to uint64_t.
sapi_status_t sapi_cast_i32_to_i16(int32_t in, int16_t *out)
Checked cast from int32_t to int16_t.
sapi_status_t sapi_cast_u64_to_u32(uint64_t in, uint32_t *out)
Checked cast from uint64_t to uint32_t.
sapi_status_t sapi_cast_i64_to_u16(int64_t in, uint16_t *out)
Checked cast from int64_t to uint16_t.
sapi_status_t sapi_cast_i8_to_u32(int8_t in, uint32_t *out)
Checked cast from int8_t to uint32_t.
sapi_status_t sapi_cast_i64_to_i32(int64_t in, int32_t *out)
Checked cast from int64_t to int32_t.
sapi_status_t sapi_cast_size_to_i32(size_t in, int32_t *out)
Checked cast from size_t to int32_t.
sapi_status_t sapi_cast_i16_to_u8(int16_t in, uint8_t *out)
Checked cast from int16_t to uint8_t.
sapi_status_t sapi_cast_i32_to_i64(int32_t in, int64_t *out)
Checked cast from int32_t to int64_t.
sapi_status_t sapi_cast_i16_to_i8(int16_t in, int8_t *out)
Checked cast from int16_t to int8_t.
sapi_status_t sapi_cast_u16_to_i8(uint16_t in, int8_t *out)
Checked cast from uint16_t to int8_t.
sapi_status_t sapi_cast_i32_to_u64(int32_t in, uint64_t *out)
Checked cast from int32_t to uint64_t.
sapi_status_t sapi_cast_u8_to_i64(uint8_t in, int64_t *out)
Checked cast from uint8_t to int64_t.
sapi_status_t sapi_cast_size_to_i64(size_t in, int64_t *out)
Checked cast from size_t to int64_t.
sapi_status_t sapi_cast_i8_to_u64(int8_t in, uint64_t *out)
Checked cast from int8_t to uint64_t.
sapi_status_t sapi_cast_i8_to_i64(int8_t in, int64_t *out)
Checked cast from int8_t to int64_t.
sapi_status_t sapi_cast_u64_to_i8(uint64_t in, int8_t *out)
Checked cast from uint64_t to int8_t.
sapi_status_t sapi_cast_i64_to_size(int64_t in, size_t *out)
Checked cast from int64_t to size_t.
sapi_status_t sapi_cast_checked_add_u32(uint32_t a, uint32_t b, uint32_t *out)
Checked addition: *out = a + b, only if the result fits uint32_t.
sapi_status_t sapi_cast_checked_mul_u32(uint32_t a, uint32_t b, uint32_t *out)
Checked multiplication: *out = a * b, only if the result fits uint32_t.
sapi_status_t sapi_cast_i32_to_size(int32_t in, size_t *out)
Checked cast from int32_t to size_t.
sapi_status_t sapi_cast_u16_to_i16(uint16_t in, int16_t *out)
Checked cast from uint16_t to int16_t.
sapi_status_t sapi_cast_u32_to_u64(uint32_t in, uint64_t *out)
Checked cast from uint32_t to uint64_t.
sapi_status_t sapi_cast_u64_to_i32(uint64_t in, int32_t *out)
Checked cast from uint64_t to int32_t.
sapi_status_t sapi_cast_i64_to_u8(int64_t in, uint8_t *out)
Checked cast from int64_t to uint8_t.
sapi_status_t sapi_cast_i32_to_u32(int32_t in, uint32_t *out)
Checked cast from int32_t to uint32_t.
sapi_status_t sapi_cast_i16_to_i32(int16_t in, int32_t *out)
Checked cast from int16_t to int32_t.
sapi_status_t sapi_cast_i32_to_i8(int32_t in, int8_t *out)
Checked cast from int32_t to int8_t.
sapi_status_t sapi_cast_checked_sub_size(size_t a, size_t b, size_t *out)
Checked subtraction: *out = a - b, only if b <= a (no underflow).
sapi_status_t sapi_cast_i8_to_u8(int8_t in, uint8_t *out)
Checked cast from int8_t to uint8_t.
void sapi_safety_violation_report(sapi_safety_violation_kind_t kind, const char *file, int32_t line, const char *message)
Reports one violation to the registered handler, if any.
@ SAPI_SAFETY_VIOLATION_OUT_OF_RANGE
@ SAPI_SAFETY_VIOLATION_OVERFLOW
sapi_status_t
Common result/status codes.
@ SAPI_STATUS_INVALID_PARAM
@ SAPI_STATUS_VALUE_OUT_OF_RANGE
Checked integer casting between all fixed-width types and size_t (ADR-003). Every conversion in the c...
Opt-in notification hook for the three new safety primitives (safe pointer, checked integer arithmeti...