[tor-commits] [tor/master] Check that all valid values of int and unsigned int can be put into void pointer

teor at torproject.org teor at torproject.org
Tue Mar 26 09:31:42 UTC 2019


commit d731ab45831cfc2104b17b3a623e0c89c3174145
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Mon Feb 25 19:07:47 2019 +0200

    Check that all valid values of int and unsigned int can be put into void pointer
---
 changes/ticket29537      |  3 +++
 src/test/include.am      |  1 +
 src/test/test.h          |  1 +
 src/test/test_ptr_slow.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/test/test_slow.c     |  1 +
 5 files changed, 73 insertions(+)

diff --git a/changes/ticket29537 b/changes/ticket29537
new file mode 100644
index 000000000..048e13c65
--- /dev/null
+++ b/changes/ticket29537
@@ -0,0 +1,3 @@
+  o Testing:
+    - Check that all valid values of `int` and `unsigned int` can be
+      represented by `void *`. Resolves issue 29537.
diff --git a/src/test/include.am b/src/test/include.am
index d585c2a38..e6cebe1d1 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -211,6 +211,7 @@ src_test_test_slow_SOURCES += \
 	src/test/test_crypto_slow.c \
 	src/test/test_process_slow.c \
 	src/test/test_prob_distr.c \
+	src/test/test_ptr_slow.c \
 	src/test/testing_common.c \
 	src/test/testing_rsakeys.c \
 	src/ext/tinytest.c
diff --git a/src/test/test.h b/src/test/test.h
index 256443298..9d9184e2a 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -278,6 +278,7 @@ extern struct testcase_t x509_tests[];
 
 extern struct testcase_t slow_crypto_tests[];
 extern struct testcase_t slow_process_tests[];
+extern struct testcase_t slow_ptr_tests[];
 
 extern struct testgroup_t testgroups[];
 
diff --git a/src/test/test_ptr_slow.c b/src/test/test_ptr_slow.c
new file mode 100644
index 000000000..a5914c912
--- /dev/null
+++ b/src/test/test_ptr_slow.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "core/or/or.h"
+#include "test/test.h"
+
+#include <stdint.h>
+#include <limits.h>
+
+/** Check that all values of int can be cast to void * and back. */
+static void
+test_int_voidstar_interop(void *arg)
+{
+  int a;
+  (void)arg;
+
+  for (a = INT_MIN; a < INT_MAX; a++) {
+   intptr_t ap = (intptr_t)a;
+   void *b = (void *)ap;
+   intptr_t c = (intptr_t)b;
+   void *d = (void *)c;
+
+   tt_assert(ap == c);
+   tt_assert(b == d);
+  }
+
+ done:
+  return;
+}
+
+/** Check that all values of unsigned int can be cast to void * and back. */
+static void
+test_uint_voidstar_interop(void *arg)
+{
+  unsigned int a;
+  (void)arg;
+
+  for (a = 0; a < UINT_MAX; a++) {
+   intptr_t ap = (intptr_t)a;
+   void *b = (void *)ap;
+   intptr_t c = (intptr_t)b;
+   void *d = (void *)c;
+
+   tt_assert(ap == c);
+   tt_assert(b == d);
+  }
+
+ done:
+  return;
+}
+
+struct testcase_t slow_ptr_tests[] = {
+  { .name = "int_voidstar_interop",
+    .fn = test_int_voidstar_interop,
+    .flags = 0,
+    .setup = NULL,
+    .setup_data = NULL },
+  { .name = "uint_voidstar_interop",
+    .fn = test_uint_voidstar_interop,
+    .flags = 0,
+    .setup = NULL,
+    .setup_data = NULL },
+  END_OF_TESTCASES
+};
diff --git a/src/test/test_slow.c b/src/test/test_slow.c
index c3e7edd40..d4d5b755a 100644
--- a/src/test/test_slow.c
+++ b/src/test/test_slow.c
@@ -22,6 +22,7 @@ struct testgroup_t testgroups[] = {
   { "slow/crypto/", slow_crypto_tests },
   { "slow/process/", slow_process_tests },
   { "slow/prob_distr/", slow_stochastic_prob_distr_tests },
+  { "slow/ptr/", slow_ptr_tests },
   END_OF_GROUPS
 };
 





More information about the tor-commits mailing list