X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fbabeltrace-internal.h;h=981f84b186910cd7145fe04cb93c30805752e36c;hb=25f741168b45db9dd975136cfd3f66dbd9af39d0;hp=1cf3af96331caf0e782937cb88978f4ee089e411;hpb=312c056ae3d374b253fa0cfe5ed576c0b0e5e569;p=babeltrace.git diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 1cf3af96..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 */