]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/_helpers.c
Fall back to calloc when __builtin_mul_overflow isn't available
[bup.git] / lib / bup / _helpers.c
index 5f13d6a1c4f932792cc05e2fdb1e3960e2136bdb..0ea5dff622e0e2cc937bb21f3bf2568e306e22fe 100644 (file)
@@ -89,6 +89,20 @@ static state_t state;
 #endif // PY_MAJOR_VERSION >= 3
 
 
+static void *checked_calloc(size_t n, size_t size)
+{
+    void *result = calloc(n, size);
+    if (!result)
+        PyErr_NoMemory();
+    return result;
+}
+
+#ifndef BUP_HAVE_BUILTIN_MUL_OVERFLOW
+
+#define checked_malloc checked_calloc
+
+#else // defined BUP_HAVE_BUILTIN_MUL_OVERFLOW
+
 static void *checked_malloc(size_t n, size_t size)
 {
     size_t total;
@@ -105,13 +119,7 @@ static void *checked_malloc(size_t n, size_t size)
     return result;
 }
 
-static void *checked_calloc(size_t n, size_t size)
-{
-    void *result = calloc(n, size);
-    if (!result)
-        PyErr_NoMemory();
-    return result;
-}
+#endif // defined BUP_HAVE_BUILTIN_MUL_OVERFLOW
 
 
 #ifndef htonll