]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Quench clang's complaints with -Wshorten-64-to-32 when time_t is not long.
authordana koch <dsk@google.com>
Sun, 11 May 2014 23:16:06 +0000 (09:16 +1000)
committerNick Mathewson <nickm@torproject.org>
Mon, 12 May 2014 03:36:00 +0000 (23:36 -0400)
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 [new file with mode: 0644]
src/common/util.c
src/or/circuituse.c
src/or/directory.c
src/or/dirserv.c
src/or/main.c
src/or/networkstatus.c
src/or/rephist.c
src/test/test_util.c

diff --git a/changes/bug11633_part2 b/changes/bug11633_part2
new file mode 100644 (file)
index 0000000..574660d
--- /dev/null
@@ -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.
index 6524be3ed87a79db54d97b28e20389f65ad20c8b..d40e83dbb1bdc3aa5fa24fcd5d249a1642274ce0 100644 (file)
@@ -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);
 }
 
index 9d2decf5768bdaf00ed98d409bd9a33dfaa6e10e..467bef652fc4f2889ea0e9a350c2ef32024d1cc0 100644 (file)
@@ -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.",
index 428fd01be4b940407f84db9eaf243b27071b3f6e..b94aac45b6ab4a2e141bbf34e9f73a68ec0db7d6 100644 (file)
@@ -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),
index 2d623a655a4f36acbf01e20f8617ffba348555b9..aedd0925223c3c46299780e7244f54b20aa9fca0 100644 (file)
@@ -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));
index 1e591577fe00478542f125782a9b50032abffcd0..5532026e392f8867f5f13fcd0f16d8a6754c5b2d 100644 (file)
@@ -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;
index 90918d4fef2300d05319a6ddcaf76cf2091c4908..890da0ad17f152ddbf959dbf1bc403a600086ed1 100644 (file)
@@ -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;
       }
index a0f24e18f787c96f1c9287eea29ad758ea0ba068..5446c25e36ba79b01b9adacaa23eaae724a7ee44 100644 (file)
@@ -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)
index d66be32a79102c3525517c4cd3859190a4276c8f..65cc58a66bbe1d40a491909f9dcf79b1567b18e8 100644 (file)
@@ -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);