Strengthen against Clang optimizations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/programs/test/metatest.c b/programs/test/metatest.c
index 91a1e2a..eb3bb76 100644
--- a/programs/test/metatest.c
+++ b/programs/test/metatest.c
@@ -11,12 +11,21 @@
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#include <mbedtls/platform.h>
+#include <mbedtls/platform_util.h>
#include "test/helpers.h"
#include <stdio.h>
#include <string.h>
+/* This is an external variable, so the compiler doesn't know that we're never
+ * changing its value.
+ *
+ * TODO: LTO (link-time-optimization) would defeat this.
+ */
+int false_but_the_compiler_does_not_know = 0;
+
+
/****************************************************************/
/* Test framework features */
/****************************************************************/
@@ -35,19 +44,17 @@
void null_pointer_dereference(const char *name)
{
(void) name;
- char *p;
- memset(&p, 0, sizeof(p));
- volatile char c;
- c = *p;
- (void) c;
+ volatile char *p;
+ mbedtls_platform_zeroize(&p, sizeof(p));
+ mbedtls_printf("%p -> %u\n", p, (unsigned) *p);
}
void null_pointer_call(const char *name)
{
(void) name;
- void (*p)(void);
- memset(&p, 0, sizeof(p));
- p();
+ unsigned (*p)(void);
+ mbedtls_platform_zeroize(&p, sizeof(p));
+ mbedtls_printf("%p() -> %u\n", p, p());
}
@@ -77,7 +84,6 @@
{
(void) name;
volatile char buf[1];
- static int false_but_the_compiler_does_not_know = 0;
if (false_but_the_compiler_does_not_know) {
buf[0] = '!';
}