Commit 12efcaae authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

include: guard overflow builtins

Pointed-out-by: default avatarKO Myung-Hun <komh78@gmail.com>
parent 964e1c13
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <stddef.h> #include <stddef.h>
#include <limits.h>
#ifndef __cplusplus #ifndef __cplusplus
# include <stdbool.h> # include <stdbool.h>
...@@ -654,7 +653,7 @@ static inline uint64_t (bswap64)(uint64_t x) ...@@ -654,7 +653,7 @@ static inline uint64_t (bswap64)(uint64_t x)
/* Integer overflow */ /* Integer overflow */
static inline bool uadd_overflow(unsigned a, unsigned b, unsigned *res) static inline bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_uadd_overflow(a, b, res); return __builtin_uadd_overflow(a, b, res);
#else #else
*res = a + b; *res = a + b;
...@@ -665,7 +664,7 @@ static inline bool uadd_overflow(unsigned a, unsigned b, unsigned *res) ...@@ -665,7 +664,7 @@ static inline bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
static inline bool uaddl_overflow(unsigned long a, unsigned long b, static inline bool uaddl_overflow(unsigned long a, unsigned long b,
unsigned long *res) unsigned long *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_uaddl_overflow(a, b, res); return __builtin_uaddl_overflow(a, b, res);
#else #else
*res = a + b; *res = a + b;
...@@ -676,7 +675,7 @@ static inline bool uaddl_overflow(unsigned long a, unsigned long b, ...@@ -676,7 +675,7 @@ static inline bool uaddl_overflow(unsigned long a, unsigned long b,
static inline bool uaddll_overflow(unsigned long long a, unsigned long long b, static inline bool uaddll_overflow(unsigned long long a, unsigned long long b,
unsigned long long *res) unsigned long long *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_uaddll_overflow(a, b, res); return __builtin_uaddll_overflow(a, b, res);
#else #else
*res = a + b; *res = a + b;
...@@ -709,9 +708,13 @@ static inline bool add_overflow(unsigned long long a, unsigned long long b, ...@@ -709,9 +708,13 @@ static inline bool add_overflow(unsigned long long a, unsigned long long b,
} }
#endif #endif
#if !(VLC_GCC_VERSION(5,0) || defined(__clang__))
# include <limits.h>
#endif
static inline bool umul_overflow(unsigned a, unsigned b, unsigned *res) static inline bool umul_overflow(unsigned a, unsigned b, unsigned *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_umul_overflow(a, b, res); return __builtin_umul_overflow(a, b, res);
#else #else
*res = a * b; *res = a * b;
...@@ -722,7 +725,7 @@ static inline bool umul_overflow(unsigned a, unsigned b, unsigned *res) ...@@ -722,7 +725,7 @@ static inline bool umul_overflow(unsigned a, unsigned b, unsigned *res)
static inline bool umull_overflow(unsigned long a, unsigned long b, static inline bool umull_overflow(unsigned long a, unsigned long b,
unsigned long *res) unsigned long *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_umull_overflow(a, b, res); return __builtin_umull_overflow(a, b, res);
#else #else
*res = a * b; *res = a * b;
...@@ -733,7 +736,7 @@ static inline bool umull_overflow(unsigned long a, unsigned long b, ...@@ -733,7 +736,7 @@ static inline bool umull_overflow(unsigned long a, unsigned long b,
static inline bool umulll_overflow(unsigned long long a, unsigned long long b, static inline bool umulll_overflow(unsigned long long a, unsigned long long b,
unsigned long long *res) unsigned long long *res)
{ {
#if defined(__GNUC__) || defined(__clang__) #if VLC_GCC_VERSION(5,0) || defined(__clang__)
return __builtin_umulll_overflow(a, b, res); return __builtin_umulll_overflow(a, b, res);
#else #else
*res = a * b; *res = a * b;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment