33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
/* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
source code may only be used and distributed under the Widevine Master
|
|
License Agreement. */
|
|
|
|
#ifndef OEMCRYPTO_TA_OEMCRYPTO_OVERFLOW_H_
|
|
#define OEMCRYPTO_TA_OEMCRYPTO_OVERFLOW_H_
|
|
|
|
/* Defines operators that check for overflow in arithmetic.
|
|
Uses the standards GNU builtins if defined and custom overflow functions
|
|
otherwise. */
|
|
|
|
/* TODO(b/145244569): Unify this with the interface for the odk. */
|
|
|
|
#ifndef __has_builtin
|
|
# define __has_builtin(x) 0
|
|
#endif
|
|
#if (defined(__GNUC__) && __GNUC__ >= 5) || \
|
|
__has_builtin(__builtin_add_overflow)
|
|
# define SubOverflowIX __builtin_sub_overflow
|
|
# define SubOverflowU32 __builtin_sub_overflow
|
|
# define SubOverflowU64 __builtin_sub_overflow
|
|
# define AddOverflowUX __builtin_add_overflow
|
|
# define SubOverflowUX __builtin_sub_overflow
|
|
#else
|
|
int SubOverflowIX(int a, int b, int* c);
|
|
int SubOverflowU32(uint32_t a, uint32_t b, uint32_t* c);
|
|
int SubOverflowU64(uint64_t a, uint64_t b, uint64_t* c);
|
|
int AddOverflowUX(size_t a, size_t b, size_t* c);
|
|
int SubOverflowUX(size_t a, size_t b, size_t* c);
|
|
#endif
|
|
|
|
#endif /* OEMCRYPTO_TA_OEMCRYPTO_OVERFLOW_H_ */
|