[tor-commits] [tor/master] Quench clang's complaints with -Wshorten-64-to-32 when time_t is not long.

nickm at torproject.org nickm at torproject.org
Mon May 12 03:41:48 UTC 2014


commit d6e6c63baf4409766ffd82fc859187b6285b093f
Author: dana koch <dsk at google.com>
Date:   Mon May 12 09:16:06 2014 +1000

    Quench clang's complaints with -Wshorten-64-to-32 when time_t is not long.
    
    On OpenBSD 5.4, time_t is a 32-bit integer. These instances contain
    implicit treatment of long and time_t as comparable types, so explicitly
    cast to time_t.
---
 changes/bug11633_part2 |    4 ++++
 src/common/util.c      |    2 +-
 src/or/circuituse.c    |   10 +++++-----
 src/or/directory.c     |    2 +-
 src/or/dirserv.c       |    2 +-
 src/or/main.c          |    2 +-
 src/or/networkstatus.c |    6 +++---
 src/or/rephist.c       |    6 +++---
 src/test/test_util.c   |    4 ++--
 9 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/changes/bug11633_part2 b/changes/bug11633_part2
new file mode 100644
index 0000000..574660d
--- /dev/null
+++ b/changes/bug11633_part2
@@ -0,0 +1,4 @@
+  o Minor bugfixes (build):
+    - Resolve clang complaints on OpenBSD with -Wshorten-64-to-32 due to
+      treatment of long and time_t as comparable types. Fixes part of bug 11633.
+      Patch from Dana Koch.
diff --git a/src/common/util.c b/src/common/util.c
index 6524be3..d40e83d 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1516,7 +1516,7 @@ void
 format_iso_time_nospace_usec(char *buf, const struct timeval *tv)
 {
   tor_assert(tv);
-  format_iso_time_nospace(buf, tv->tv_sec);
+  format_iso_time_nospace(buf, (time_t)tv->tv_sec);
   tor_snprintf(buf+ISO_TIME_LEN, 8, ".%06d", (int)tv->tv_usec);
 }
 
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 9d2decf..467bef6 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -296,7 +296,7 @@ circuit_get_best(const entry_connection_t *conn,
     }
 
     if (!circuit_is_acceptable(origin_circ,conn,must_be_open,purpose,
-                               need_uptime,need_internal,now.tv_sec))
+                               need_uptime,need_internal, (time_t)now.tv_sec))
       continue;
 
     /* now this is an acceptable circ to hand back. but that doesn't
@@ -683,9 +683,9 @@ circuit_expire_building(void)
                      victim->purpose,
                      circuit_purpose_to_string(victim->purpose));
         } else if (circuit_build_times_count_close(
-                                         get_circuit_build_times_mutable(),
-                                         first_hop_succeeded,
-                                         victim->timestamp_created.tv_sec)) {
+            get_circuit_build_times_mutable(),
+            first_hop_succeeded,
+            (time_t)victim->timestamp_created.tv_sec)) {
           circuit_build_times_set_timeout(get_circuit_build_times_mutable());
         }
       }
@@ -825,7 +825,7 @@ circuit_log_ancient_one_hop_circuits(int age)
     char created[ISO_TIME_LEN+1];
     circ = TO_CIRCUIT(ocirc);
     format_local_iso_time(created,
-                          circ->timestamp_created.tv_sec);
+                          (time_t)circ->timestamp_created.tv_sec);
 
     log_notice(LD_HEARTBEAT, "  #%d created at %s. %s, %s. %s for close. "
                "%s for new conns.",
diff --git a/src/or/directory.c b/src/or/directory.c
index 428fd01..b94aac4 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2299,7 +2299,7 @@ write_http_response_header_impl(dir_connection_t *conn, ssize_t length,
   }
   if (cache_lifetime > 0) {
     char expbuf[RFC1123_TIME_LEN+1];
-    format_rfc1123_time(expbuf, now + cache_lifetime);
+    format_rfc1123_time(expbuf, (time_t)(now + cache_lifetime));
     /* We could say 'Cache-control: max-age=%d' here if we start doing
      * http/1.1 */
     tor_snprintf(cp, sizeof(tmp)-(cp-tmp),
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 2d623a6..aedd092 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2507,7 +2507,7 @@ dirserv_read_measured_bandwidths(const char *from_file,
   }
 
   line[strlen(line)-1] = '\0';
-  file_time = tor_parse_ulong(line, 10, 0, ULONG_MAX, &ok, NULL);
+  file_time = (time_t)tor_parse_ulong(line, 10, 0, ULONG_MAX, &ok, NULL);
   if (!ok) {
     log_warn(LD_DIRSERV, "Non-integer time in bandwidth file: %s",
              escaped(line));
diff --git a/src/or/main.c b/src/or/main.c
index 1e59157..5532026 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1755,7 +1755,7 @@ refill_callback(periodic_timer_t *timer, void *arg)
     accounting_add_bytes(bytes_read, bytes_written, seconds_rolled_over);
 
   if (milliseconds_elapsed > 0)
-    connection_bucket_refill(milliseconds_elapsed, now.tv_sec);
+    connection_bucket_refill(milliseconds_elapsed, (time_t)now.tv_sec);
 
   stats_prev_global_read_bucket = global_read_bucket;
   stats_prev_global_write_bucket = global_write_bucket;
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 90918d4..890da0a 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -830,7 +830,7 @@ update_consensus_networkstatus_fetch_time_impl(time_t now, int flav)
     if (directory_fetches_dir_info_early(options)) {
       /* We want to cache the next one at some point after this one
        * is no longer fresh... */
-      start = c->fresh_until + min_sec_before_caching;
+      start = (time_t)(c->fresh_until + min_sec_before_caching);
       /* Some clients may need the consensus sooner than others. */
       if (options->FetchDirInfoExtraEarly || authdir_mode_v3(options)) {
         dl_interval = 60;
@@ -843,7 +843,7 @@ update_consensus_networkstatus_fetch_time_impl(time_t now, int flav)
     } else {
       /* We're an ordinary client or a bridge. Give all the caches enough
        * time to download the consensus. */
-      start = c->fresh_until + (interval*3)/4;
+      start = (time_t)(c->fresh_until + (interval*3)/4);
       /* But download the next one well before this one is expired. */
       dl_interval = ((c->valid_until - start) * 7 )/ 8;
 
@@ -851,7 +851,7 @@ update_consensus_networkstatus_fetch_time_impl(time_t now, int flav)
        * to choose the rest of the interval *after* them. */
       if (directory_fetches_dir_info_later(options)) {
         /* Give all the *clients* enough time to download the consensus. */
-        start = start + dl_interval + min_sec_before_caching;
+        start = (time_t)(start + dl_interval + min_sec_before_caching);
         /* But try to get it before ours actually expires. */
         dl_interval = (c->valid_until - start) - min_sec_before_caching;
       }
diff --git a/src/or/rephist.c b/src/or/rephist.c
index a0f24e1..5446c25 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -931,7 +931,7 @@ correct_time(time_t t, time_t now, time_t stored_at, time_t started_measuring)
     return 0;
   else {
     long run_length = stored_at - t;
-    t = now - run_length;
+    t = (time_t)(now - run_length);
     if (t < started_measuring)
       t = started_measuring;
     return t;
@@ -1092,7 +1092,7 @@ rep_hist_load_mtbf_data(time_t now)
       hist->start_of_run = correct_time(start_of_run, now, stored_at,
                                         tracked_since);
       if (hist->start_of_run < latest_possible_start + wrl)
-        latest_possible_start = hist->start_of_run - wrl;
+        latest_possible_start = (time_t)(hist->start_of_run - wrl);
 
       hist->weighted_run_length = wrl;
       hist->total_run_weights = trw;
@@ -2311,7 +2311,7 @@ rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
     return;
   start_of_interval = (circ->timestamp_created.tv_sec >
                        start_of_buffer_stats_interval) ?
-        circ->timestamp_created.tv_sec :
+        (time_t)circ->timestamp_created.tv_sec :
         start_of_buffer_stats_interval;
   interval_length = (int) (end_of_interval - start_of_interval);
   if (interval_length <= 0)
diff --git a/src/test/test_util.c b/src/test/test_util.c
index d66be32..65cc58a 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -344,7 +344,7 @@ test_util_time(void)
 
   tv.tv_sec = (time_t)1326296338;
   tv.tv_usec = 3060;
-  format_iso_time(timestr, tv.tv_sec);
+  format_iso_time(timestr, (time_t)tv.tv_sec);
   test_streq("2012-01-11 15:38:58", timestr);
   /* The output of format_local_iso_time will vary by timezone, and setting
      our timezone for testing purposes would be a nontrivial flaky pain.
@@ -352,7 +352,7 @@ test_util_time(void)
   format_local_iso_time(timestr, tv.tv_sec);
   test_streq("2012-01-11 10:38:58", timestr);
   */
-  format_iso_time_nospace(timestr, tv.tv_sec);
+  format_iso_time_nospace(timestr, (time_t)tv.tv_sec);
   test_streq("2012-01-11T15:38:58", timestr);
   test_eq(strlen(timestr), ISO_TIME_LEN);
   format_iso_time_nospace_usec(timestr, &tv);





More information about the tor-commits mailing list