Преглед на файлове

Make GCC very happy, even with lots of warnings set. Also, try to fix some reported Solaris x86 warnings.

svn:r4770
Nick Mathewson преди 19 години
родител
ревизия
789374dbbd
променени са 8 файла, в които са добавени 70 реда и са изтрити 45 реда
  1. 3 0
      src/common/compat.h
  2. 6 0
      src/common/log.c
  3. 20 13
      src/common/test.h
  4. 3 0
      src/common/util.c
  5. 1 1
      src/or/circuitbuild.c
  6. 2 1
      src/or/config.c
  7. 6 1
      src/or/control.c
  8. 29 29
      src/or/test.c

+ 3 - 0
src/common/compat.h

@@ -26,6 +26,9 @@
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
 #include <stdarg.h>
 
 #ifndef NULL_REP_IS_ZERO_BYTES

+ 6 - 0
src/common/log.c

@@ -14,6 +14,12 @@ const char log_c_id[] = "$Id$";
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
 #include "./util.h"
 #include "./log.h"
 

+ 20 - 13
src/common/test.h

@@ -49,21 +49,28 @@ extern int have_failed;
     return;                                                     \
   } STMT_END
 
-#define test_eq(expr1, expr2)                                   \
-  STMT_BEGIN                                                    \
-    long v1=(long)(expr1), v2=(long)(expr2);                    \
-    if (v1==v2) { printf("."); fflush(stdout); } else {         \
-    have_failed = 1;                                            \
-    printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
-           "      (%ld != %ld)\n",                              \
-      _SHORT_FILE_,                                             \
-      __LINE__,                                                 \
-      PRETTY_FUNCTION,                                          \
-      #expr1, #expr2,                                           \
-      v1, v2);                                                  \
-    return;                                                     \
+#define test_eq_type(tp, fmt, expr1, expr2) \
+  STMT_BEGIN                                                            \
+  tp v1=(tp)(expr1);                                                    \
+  tp v2=(tp)(expr2);                                                    \
+  if (v1==v2) { printf("."); fflush(stdout); } else {                   \
+    have_failed = 1;                                                    \
+    printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"      \
+           "      "fmt "!="fmt"\n",                                     \
+             _SHORT_FILE_,                                              \
+             __LINE__,                                                  \
+             PRETTY_FUNCTION,                                           \
+             #expr1, #expr2,                                            \
+             v1, v2);                                                   \
+    return;                                                             \
   } STMT_END
 
+#define test_eq(expr1, expr2)                   \
+  test_eq_type(long, "%ld", expr1, expr2)
+
+#define test_eq_ptr(expr1, expr2)               \
+  test_eq_type(void*, "%p", expr1, expr2)
+
 #define test_neq(expr1, expr2)                                  \
   STMT_BEGIN                                                    \
     long v1=(long)(expr1), v2=(long)(expr2);                    \

+ 3 - 0
src/common/util.c

@@ -77,6 +77,9 @@ const char util_c_id[] = "$Id$";
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
 
 #ifndef O_BINARY
 #define O_BINARY 0

+ 1 - 1
src/or/circuitbuild.c

@@ -1672,7 +1672,7 @@ remove_dead_helpers(void)
 
   for (i = 0; i < smartlist_len(helper_nodes); ) {
     helper_node_t *helper = smartlist_get(helper_nodes, i);
-    char *why = NULL;
+    const char *why = NULL;
     time_t since = 0;
     if (helper->unlisted_since + HELPER_ALLOW_UNLISTED > now) {
       why = "unlisted";

+ 2 - 1
src/or/config.c

@@ -291,6 +291,8 @@ static int init_libevent(void);
 static void check_libevent_version(const char *m, const char *v, int server);
 #endif
 
+/*static*/ or_options_t *options_new(void);
+
 #define OR_OPTIONS_MAGIC 9090909
 
 static config_format_t options_format = {
@@ -2213,7 +2215,6 @@ get_torrc_fname(void)
     return get_default_conf_file();
 }
 
-
 /** Adjust the address map mased on the MapAddress elements in the
  * configuration <b>options</b>
  */

+ 6 - 1
src/or/control.c

@@ -127,6 +127,10 @@ static char authentication_cookie[AUTHENTICATION_COOKIE_LEN];
 
 static void connection_printf_to_buf(connection_t *conn, const char *format, ...)
   CHECK_PRINTF(2,3);
+/*static*/ size_t write_escaped_data(const char *data, size_t len,
+                                     int translate_newlines, char **out);
+/*static*/ size_t read_escaped_data(const char *data, size_t len,
+                                    int translate_newlines,  char **out);
 static void send_control0_message(connection_t *conn, uint16_t type,
                                  uint32_t len, const char *body);
 static void send_control_done(connection_t *conn);
@@ -1883,7 +1887,8 @@ connection_control_reached_eof(connection_t *conn)
 static int
 connection_control_process_inbuf_v1(connection_t *conn)
 {
-  size_t data_len, cmd_len;
+  size_t data_len;
+  int cmd_len;
   char *args;
 
   tor_assert(conn);

+ 29 - 29
src/or/test.c

@@ -676,12 +676,12 @@ test_util(void)
   smartlist_insert(sl, 1, (void*)22);
   smartlist_insert(sl, 0, (void*)0);
   smartlist_insert(sl, 5, (void*)555);
-  test_eq((void*)0,   smartlist_get(sl,0));
-  test_eq((void*)1,   smartlist_get(sl,1));
-  test_eq((void*)22,  smartlist_get(sl,2));
-  test_eq((void*)3,   smartlist_get(sl,3));
-  test_eq((void*)4,   smartlist_get(sl,4));
-  test_eq((void*)555, smartlist_get(sl,5));
+  test_eq_ptr((void*)0,   smartlist_get(sl,0));
+  test_eq_ptr((void*)1,   smartlist_get(sl,1));
+  test_eq_ptr((void*)22,  smartlist_get(sl,2));
+  test_eq_ptr((void*)3,   smartlist_get(sl,3));
+  test_eq_ptr((void*)4,   smartlist_get(sl,4));
+  test_eq_ptr((void*)555, smartlist_get(sl,5));
 
   smartlist_clear(sl);
   smartlist_split_string(sl, "abc", ":", 0, 0);
@@ -968,14 +968,14 @@ test_strmap(void)
   test_eq(v, NULL);
   v = strmap_set(map, "K1", (void*)100);
   test_eq(v, (void*)99);
-  test_eq(strmap_get(map,"K1"), (void*)100);
-  test_eq(strmap_get(map,"K2"), (void*)101);
-  test_eq(strmap_get(map,"K-not-there"), NULL);
+  test_eq_ptr(strmap_get(map,"K1"), (void*)100);
+  test_eq_ptr(strmap_get(map,"K2"), (void*)101);
+  test_eq_ptr(strmap_get(map,"K-not-there"), NULL);
 
   v = strmap_remove(map,"K2");
-  test_eq(v, (void*)101);
-  test_eq(strmap_get(map,"K2"), NULL);
-  test_eq(strmap_remove(map,"K2"), NULL);
+  test_eq_ptr(v, (void*)101);
+  test_eq_ptr(strmap_get(map,"K2"), NULL);
+  test_eq_ptr(strmap_remove(map,"K2"), NULL);
 
   strmap_set(map, "K2", (void*)101);
   strmap_set(map, "K3", (void*)102);
@@ -986,9 +986,9 @@ test_strmap(void)
   count = 0;
   strmap_foreach(map, _squareAndRemoveK4, &count);
   test_eq(count, 1);
-  test_eq(strmap_get(map, "K4"), NULL);
-  test_eq(strmap_get(map, "K1"), (void*)10000);
-  test_eq(strmap_get(map, "K6"), (void*)11025);
+  test_eq_ptr(strmap_get(map, "K4"), NULL);
+  test_eq_ptr(strmap_get(map, "K1"), (void*)10000);
+  test_eq_ptr(strmap_get(map, "K6"), (void*)11025);
 
   iter = strmap_iter_init(map);
   strmap_iter_get(iter,&k,&v);
@@ -1010,8 +1010,8 @@ test_strmap(void)
   test_assert(strmap_iter_done(iter));
 
   /* Make sure we removed K2, but not the others. */
-  test_eq(strmap_get(map, "K2"), NULL);
-  test_eq(strmap_get(map, "K5"), (void*)10816);
+  test_eq_ptr(strmap_get(map, "K2"), NULL);
+  test_eq_ptr(strmap_get(map, "K5"), (void*)10816);
 
   /* Clean up after ourselves. */
   strmap_free(map, NULL);
@@ -1019,11 +1019,11 @@ test_strmap(void)
   /* Now try some lc functions. */
   map = strmap_new();
   strmap_set_lc(map,"Ab.C", (void*)1);
-  test_eq(strmap_get(map,"ab.c"), (void*)1);
-  test_eq(strmap_get_lc(map,"AB.C"), (void*)1);
-  test_eq(strmap_get(map,"AB.C"), NULL);
-  test_eq(strmap_remove_lc(map,"aB.C"), (void*)1);
-  test_eq(strmap_get_lc(map,"AB.C"), NULL);
+  test_eq_ptr(strmap_get(map,"ab.c"), (void*)1);
+  test_eq_ptr(strmap_get_lc(map,"AB.C"), (void*)1);
+  test_eq_ptr(strmap_get(map,"AB.C"), NULL);
+  test_eq_ptr(strmap_remove_lc(map,"aB.C"), (void*)1);
+  test_eq_ptr(strmap_get_lc(map,"AB.C"), NULL);
   strmap_free(map,NULL);
 }
 
@@ -1396,11 +1396,11 @@ test_exit_policies(void)
   test_streq("reject 192.168.0.0/16:*", policy->string);
 
   test_assert(exit_policy_implicitly_allows_local_networks(policy, 0));
-  test_eq(ADDR_POLICY_ACCEPTED,
+  test_assert(ADDR_POLICY_ACCEPTED ==
           router_compare_addr_to_addr_policy(0x01020304u, 2, policy));
-  test_eq(ADDR_POLICY_PROBABLY_ACCEPTED,
+  test_assert(ADDR_POLICY_PROBABLY_ACCEPTED ==
           router_compare_addr_to_addr_policy(0, 2, policy));
-  test_eq(ADDR_POLICY_REJECTED,
+  test_assert(ADDR_POLICY_REJECTED ==
           router_compare_addr_to_addr_policy(0xc0a80102, 2, policy));
 
   addr_policy_free(policy);
@@ -1509,10 +1509,10 @@ test_rend_fns(void)
   test_memeq(d2->intro_point_extend_info[1]->identity_digest,
              d1->intro_point_extend_info[1]->identity_digest, DIGEST_LEN);
 
-  test_eq(BAD_HOSTNAME, parse_extended_hostname(address1));
-  test_eq(ONION_HOSTNAME, parse_extended_hostname(address2));
-  test_eq(EXIT_HOSTNAME, parse_extended_hostname(address3));
-  test_eq(NORMAL_HOSTNAME, parse_extended_hostname(address4));
+  test_assert(BAD_HOSTNAME == parse_extended_hostname(address1));
+  test_assert(ONION_HOSTNAME == parse_extended_hostname(address2));
+  test_assert(EXIT_HOSTNAME == parse_extended_hostname(address3));
+  test_assert(NORMAL_HOSTNAME == parse_extended_hostname(address4));
 
   rend_service_descriptor_free(d1);
   rend_service_descriptor_free(d2);