summaryrefslogtreecommitdiffstats
path: root/src/lib/safe-memset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/safe-memset.c')
-rw-r--r--src/lib/safe-memset.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/safe-memset.c b/src/lib/safe-memset.c
new file mode 100644
index 0000000..3062a41
--- /dev/null
+++ b/src/lib/safe-memset.c
@@ -0,0 +1,17 @@
+/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "safe-memset.h"
+
+void safe_memset(void *data, int c, size_t size)
+{
+ volatile unsigned int volatile_zero_idx = 0;
+ volatile unsigned char *p = data;
+
+ if (size == 0)
+ return;
+
+ do {
+ memset(data, c, size);
+ } while (p[volatile_zero_idx] != c);
+}