aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-30 10:37:58 -0400
committerJack Lloyd <[email protected]>2017-09-30 10:37:58 -0400
commit39d4dfdba31c098f77cd4e079b0eea643142fb67 (patch)
tree2fa4e24cb9d8dbb2cee195a014f2fb0bfbb12dd2 /src/lib
parenta791b99331a58452c290dd2bb24b2648d93274aa (diff)
Add annotation so GCC/Clang/MSVC know it is an allocation function.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/utils/compiler.h11
-rw-r--r--src/lib/utils/mem_ops.h2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/lib/utils/compiler.h b/src/lib/utils/compiler.h
index 00f22358a..9ef0f75b3 100644
--- a/src/lib/utils/compiler.h
+++ b/src/lib/utils/compiler.h
@@ -85,6 +85,17 @@
#endif
/*
+* Define BOTAN_MALLOC_FN
+*/
+#if defined(__GNUG__) || defined(__clang__)
+ #define BOTAN_MALLOC_FN __attribute__ ((malloc))
+#elif defined(_MSC_VER)
+ #define BOTAN_MALLOC_FN __declspec(restrict)
+#else
+ #define BOTAN_MALLOC_FN
+#endif
+
+/*
* Define BOTAN_DEPRECATED
*/
#if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
diff --git a/src/lib/utils/mem_ops.h b/src/lib/utils/mem_ops.h
index 4b03b23d2..3274bfaf6 100644
--- a/src/lib/utils/mem_ops.h
+++ b/src/lib/utils/mem_ops.h
@@ -22,7 +22,7 @@ namespace Botan {
* @param elem_size the size of each element
* @return pointer to allocated and zeroed memory, or throw std::bad_alloc on failure
*/
-BOTAN_PUBLIC_API(2,3) void* allocate_memory(size_t elems, size_t elem_size);
+BOTAN_PUBLIC_API(2,3) BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size);
/**
* Free a pointer returned by allocate_memory