Browse Source

Use -Wdouble-promotion in GCC >= 4.6

This warning triggers on silently promoting a float to a double.  In
our code, it's just a sign that somebody used a float by mistake,
since we always prefer double.
Nick Mathewson 8 years ago
parent
commit
8f2d2933f9
5 changed files with 19 additions and 17 deletions
  1. 1 0
      configure.ac
  2. 1 1
      src/or/channel.c
  3. 2 1
      src/or/channeltls.c
  4. 8 8
      src/test/test_channel.c
  5. 7 7
      src/test/test_channeltls.c

+ 1 - 0
configure.ac

@@ -1756,6 +1756,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
     CFLAGS="$CFLAGS -Wlogical-op"
     # and these should be just fine in gcc 4.6
     CFLAGS="$CFLAGS -Wmissing-format-attribute -Wsuggest-attribute=noreturn -Wsync-nand -Wtrampolines -Wunused-but-set-parameter -Wunused-but-set-variable -Wvariadic-macros"
+    CFLAGS="$CFLAGS -Wdouble-promotion"
   fi
 
   if test "x$have_gcc47" = "xyes"; then

+ 1 - 1
src/or/channel.c

@@ -4524,7 +4524,7 @@ channel_update_xmit_queue_size(channel_t *chan)
   /* Next, adjust by the overhead factor, if any is available */
   if (chan->get_overhead_estimate) {
     overhead = chan->get_overhead_estimate(chan);
-    if (overhead >= 1.0f) {
+    if (overhead >= 1.0) {
       queued = (uint64_t)(queued * overhead);
     } else {
       /* Ignore silly overhead factors */

+ 2 - 1
src/or/channeltls.c

@@ -462,7 +462,8 @@ channel_tls_get_overhead_estimate_method(channel_t *chan)
      * Never estimate more than 2.0; otherwise we get silly large estimates
      * at the very start of a new TLS connection.
      */
-    if (overhead > 2.0f) overhead = 2.0f;
+    if (overhead > 2.0)
+      overhead = 2.0;
   }
 
   log_debug(LD_CHANNEL,

+ 8 - 8
src/test/test_channel.c

@@ -33,7 +33,7 @@ static int test_destroy_not_pending_calls = 0;
 static int test_doesnt_want_writes_count = 0;
 static int test_dumpstats_calls = 0;
 static int test_has_waiting_cells_count = 0;
-static double test_overhead_estimate = 1.0f;
+static double test_overhead_estimate = 1.0;
 static int test_releases_count = 0;
 static circuitmux_t *test_target_cmux = NULL;
 static unsigned int test_cmux_cells = 0;
@@ -792,7 +792,7 @@ test_channel_incoming(void *arg)
   /* Accept cells to lower layer */
   test_chan_accept_cells = 1;
   /* Use default overhead factor */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
 
   ch = new_fake_channel();
   tt_assert(ch);
@@ -881,7 +881,7 @@ test_channel_lifecycle(void *arg)
   /* Accept cells to lower layer */
   test_chan_accept_cells = 1;
   /* Use default overhead factor */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
 
   ch1 = new_fake_channel();
   tt_assert(ch1);
@@ -989,7 +989,7 @@ test_channel_lifecycle_2(void *arg)
   /* Accept cells to lower layer */
   test_chan_accept_cells = 1;
   /* Use default overhead factor */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
 
   ch = new_fake_channel();
   tt_assert(ch);
@@ -1136,7 +1136,7 @@ test_channel_multi(void *arg)
   /* Accept cells to lower layer */
   test_chan_accept_cells = 1;
   /* Use default overhead factor */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
 
   ch1 = new_fake_channel();
   tt_assert(ch1);
@@ -1444,7 +1444,7 @@ test_channel_queue_incoming(void *arg)
   /* Accept cells to lower layer */
   test_chan_accept_cells = 1;
   /* Use default overhead factor */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
 
   ch = new_fake_channel();
   tt_assert(ch);
@@ -1589,11 +1589,11 @@ test_channel_queue_size(void *arg)
   channel_update_xmit_queue_size(ch);
   tt_u64_op(ch->bytes_queued_for_xmit, ==, 512);
   /* Now try a larger one */
-  test_overhead_estimate = 2.0f;
+  test_overhead_estimate = 2.0;
   channel_update_xmit_queue_size(ch);
   tt_u64_op(ch->bytes_queued_for_xmit, ==, 1024);
   /* Go back to 1.0 */
-  test_overhead_estimate = 1.0f;
+  test_overhead_estimate = 1.0;
   channel_update_xmit_queue_size(ch);
   tt_u64_op(ch->bytes_queued_for_xmit, ==, 512);
   /* Check the global estimate too */

+ 7 - 7
src/test/test_channeltls.c

@@ -206,31 +206,31 @@ test_channeltls_overhead_estimate(void *arg)
   ch = channel_tls_connect(&test_addr, 567, test_digest);
   tt_assert(ch != NULL);
 
-  /* First case: silly low ratios should get clamped to 1.0f */
+  /* First case: silly low ratios should get clamped to 1.0 */
   tlschan = BASE_CHAN_TO_TLS(ch);
   tt_assert(tlschan != NULL);
   tlschan->conn->bytes_xmitted = 128;
   tlschan->conn->bytes_xmitted_by_tls = 64;
   r = ch->get_overhead_estimate(ch);
-  tt_assert(fabs(r - 1.0f) < 1E-12);
+  tt_assert(fabs(r - 1.0) < 1E-12);
 
   tlschan->conn->bytes_xmitted_by_tls = 127;
   r = ch->get_overhead_estimate(ch);
-  tt_assert(fabs(r - 1.0f) < 1E-12);
+  tt_assert(fabs(r - 1.0) < 1E-12);
 
   /* Now middle of the range */
   tlschan->conn->bytes_xmitted_by_tls = 192;
   r = ch->get_overhead_estimate(ch);
-  tt_assert(fabs(r - 1.5f) < 1E-12);
+  tt_assert(fabs(r - 1.5) < 1E-12);
 
-  /* Now above the 2.0f clamp */
+  /* Now above the 2.0 clamp */
   tlschan->conn->bytes_xmitted_by_tls = 257;
   r = ch->get_overhead_estimate(ch);
-  tt_assert(fabs(r - 2.0f) < 1E-12);
+  tt_assert(fabs(r - 2.0) < 1E-12);
 
   tlschan->conn->bytes_xmitted_by_tls = 512;
   r = ch->get_overhead_estimate(ch);
-  tt_assert(fabs(r - 2.0f) < 1E-12);
+  tt_assert(fabs(r - 2.0) < 1E-12);
 
  done:
   if (ch) {