[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Fix another int-to-ptr cast.



commit ba17968534ea51bbf5e3a0ab0cf4da97ef895252
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri May 29 14:09:11 2015 -0400

    Fix another int-to-ptr cast.
---
 src/test/test_scheduler.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/test/test_scheduler.c b/src/test/test_scheduler.c
index 73a4220..79a5534 100644
--- a/src/test/test_scheduler.c
+++ b/src/test/test_scheduler.c
@@ -38,9 +38,9 @@ static circuitmux_t *mock_ccm_tgt_1 = NULL;
 static circuitmux_t *mock_ccm_tgt_2 = NULL;
 
 static circuitmux_t *mock_cgp_tgt_1 = NULL;
-static const circuitmux_policy_t *mock_cgp_val_1 = NULL;
+static circuitmux_policy_t *mock_cgp_val_1 = NULL;
 static circuitmux_t *mock_cgp_tgt_2 = NULL;
-static const circuitmux_policy_t *mock_cgp_val_2 = NULL;
+static circuitmux_policy_t *mock_cgp_val_2 = NULL;
 static int scheduler_compare_channels_mock_ctr = 0;
 static int scheduler_run_mock_ctr = 0;
 
@@ -457,13 +457,19 @@ test_scheduler_compare_channels(void *arg)
 
   /* Configure circuitmux_get_policy() mock */
   mock_cgp_tgt_1 = cm1;
+  mock_cgp_tgt_2 = cm2;
+
   /*
    * This is to test the different-policies case, which uses the policy
    * cast to an intptr_t as an arbitrary but definite thing to compare.
    */
-  mock_cgp_val_1 = (const circuitmux_policy_t *)(1);
-  mock_cgp_tgt_2 = cm2;
-  mock_cgp_val_2 = (const circuitmux_policy_t *)(2);
+  mock_cgp_val_1 = tor_malloc_zero(16);
+  mock_cgp_val_2 = tor_malloc_zero(16);
+  if ( ((intptr_t) mock_cgp_val_1) > ((intptr_t) mock_cgp_val_2) ) {
+    void *tmp = mock_cgp_val_1;
+    mock_cgp_val_1 = mock_cgp_val_2;
+    mock_cgp_val_2 = tmp;
+  }
 
   MOCK(circuitmux_get_policy, circuitmux_get_policy_mock);
 
@@ -483,6 +489,7 @@ test_scheduler_compare_channels(void *arg)
   tt_int_op(result, ==, 1);
 
   /* Distinct channels, same policy */
+  tor_free(mock_cgp_val_2);
   mock_cgp_val_2 = mock_cgp_val_1;
   result = scheduler_compare_channels(&c1, &c2);
   tt_int_op(result, ==, -1);
@@ -497,13 +504,17 @@ test_scheduler_compare_channels(void *arg)
 
   UNMOCK(circuitmux_get_policy);
   mock_cgp_tgt_1 = NULL;
-  mock_cgp_val_1 = NULL;
   mock_cgp_tgt_2 = NULL;
-  mock_cgp_val_2 = NULL;
 
   tor_free(cm1);
   tor_free(cm2);
 
+  if (mock_cgp_val_1 != mock_cgp_val_2)
+    tor_free(mock_cgp_val_1);
+  tor_free(mock_cgp_val_2);
+  mock_cgp_val_1 = NULL;
+  mock_cgp_val_2 = NULL;
+
   return;
 }
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits