Cleanup: remove private babeltrace.h
[babeltrace.git] / src / common / safe.h
diff --git a/src/common/safe.h b/src/common/safe.h
new file mode 100644 (file)
index 0000000..26df90a
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include <stdbool.h>
+#include <stdint.h>
+
+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;
+}
This page took 0.023512 seconds and 4 git commands to generate.