X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fbabeltrace-internal.h;h=981f84b186910cd7145fe04cb93c30805752e36c;hb=5b9e151d6a8c0327e67bca1706ef16525d1d319d;hp=1bdd79ece3ee19e6ca5b6005f9cf9ed21b6adf09;hpb=b4565e8b2e0f7c0e356919fe95b760bed7a71d1b;p=babeltrace.git diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 1bdd79ec..981f84b1 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_INTERNAL_H /* - * babeltrace/babeltrace-internal.h - * * Copyright 2012 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -28,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +62,38 @@ ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) #endif +static inline +bool bt_safe_to_mul_int64(int64_t a, int64_t b) +{ + if (a == 0 || b == 0) { + return true; + } + + return a < INT64_MAX / b; +} + +static inline +bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b) +{ + if (a == 0 || b == 0) { + return true; + } + + return a < UINT64_MAX / b; +} + +static inline +bool bt_safe_to_add_int64(int64_t a, int64_t b) +{ + return a <= INT64_MAX - b; +} + +static inline +bool bt_safe_to_add_uint64(uint64_t a, uint64_t b) +{ + return a <= UINT64_MAX - b; +} + /* * Memory allocation zeroed */ @@ -79,7 +110,12 @@ #define BT_HIDDEN __attribute__((visibility("hidden"))) #endif +#ifndef __STRINGIFY #define __STRINGIFY(x) #x +#endif + #define TOSTRING(x) __STRINGIFY(x) +#define BT_UNUSED __attribute__((unused)) + #endif