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

[tor-dev] [PATCH] Fix some compiler warnings (torsocks)



I fixed some compiler warnings that came up with my standard gcc flags,
nothing serious.

BTW, the code uses some gcc extensions which are not compatible through
compilers and/or systems:
- pointer arithmetic with void *
- function pointer and void * assignments
- gcc variadic macro extensions

FYI, my gcc flags are
-std=gnu99 -pedantic -O2 -g -Wall -Wextra -Wstrict-prototypes -Wold-style-
definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-
code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -
Wlogical-op -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -
D_FORTIFY_SOURCE=2

Regards, Tim
From f0caa430619c4b39184e5e3c5057f4f79f0d2f78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim RÃhsen?= <tim.ruehsen@xxxxxx>
Date: Fri, 23 Jan 2015 10:31:33 +0100
Subject: [PATCH] Fix some compiler warnings

---
 src/common/connection.c |  4 ++--
 src/common/connection.h |  2 +-
 src/common/log.h        |  2 +-
 src/common/onion.c      |  6 +++---
 src/lib/recv.c          |  5 +++--
 src/lib/torsocks.h      |  2 +-
 tests/test_fd_passing.c |  4 ++--
 tests/utils/tap/tap.c   | 12 ++++++------
 tests/utils/tap/tap.h   |  8 ++++----
 9 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/src/common/connection.c b/src/common/connection.c
index 4c75579..0a75241 100644
--- a/src/common/connection.c
+++ b/src/common/connection.c
@@ -84,9 +84,9 @@ static inline unsigned int conn_hash_fct(struct connection *c)
  */
 static HT_HEAD(connection_registry, connection) connection_registry_root;
 HT_PROTOTYPE(connection_registry, connection, node, conn_hash_fct,
-		conn_equal_fct);
+		conn_equal_fct)
 HT_GENERATE(connection_registry, connection, node, conn_hash_fct,
-		conn_equal_fct, 0.5, malloc, realloc, free);
+		conn_equal_fct, 0.5, malloc, realloc, free)

 /*
  * Acquire connection registry mutex.
diff --git a/src/common/connection.h b/src/common/connection.h
index 379f158..8db253e 100644
--- a/src/common/connection.h
+++ b/src/common/connection.h
@@ -30,7 +30,7 @@
 enum connection_domain {
 	CONNECTION_DOMAIN_INET	= 1,
 	CONNECTION_DOMAIN_INET6	= 2,
-	CONNECTION_DOMAIN_NAME  = 3,
+	CONNECTION_DOMAIN_NAME  = 3
 };

 /*
diff --git a/src/common/log.h b/src/common/log.h
index 0423aee..92eb659 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -43,7 +43,7 @@
  */
 enum log_time_status {
 	LOG_TIME_NONE	= 0,
-	LOG_TIME_ADD	= 1,
+	LOG_TIME_ADD	= 1
 };

 extern int tsocks_loglevel;
diff --git a/src/common/onion.c b/src/common/onion.c
index 67b4297..73d17c6 100644
--- a/src/common/onion.c
+++ b/src/common/onion.c
@@ -141,7 +141,7 @@ error:
 ATTR_HIDDEN
 void onion_pool_destroy(struct onion_pool *pool)
 {
-	int i;
+	unsigned i;

 	assert(pool);

@@ -220,7 +220,7 @@ ATTR_HIDDEN
 struct onion_entry *onion_entry_find_by_name(const char *onion_name,
 		struct onion_pool *pool)
 {
-	int i;
+	unsigned i;
 	struct onion_entry *entry = NULL;

 	assert(onion_name);
@@ -251,7 +251,7 @@ ATTR_HIDDEN
 struct onion_entry *onion_entry_find_by_addr(const struct sockaddr *sa,
 		struct onion_pool *pool)
 {
-	int i;
+	unsigned i;
 	struct onion_entry *entry = NULL;
 	const struct sockaddr_in *sin;

diff --git a/src/lib/recv.c b/src/lib/recv.c
index 6e8a20a..972a884 100644
--- a/src/lib/recv.c
+++ b/src/lib/recv.c
@@ -39,7 +39,7 @@ TSOCKS_LIBC_DECL(recvmsg, LIBC_RECVMSG_RET_TYPE, LIBC_RECVMSG_SIG)
  */
 static void close_fds(int *fds, size_t count)
 {
-	int i;
+	unsigned i;

 	for (i = 0; i < count; i++) {
 		tsocks_libc_close(fds[i]);
@@ -125,7 +125,8 @@ LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG)
 		 * stack memory.
 		 */
 		size_t sizeof_fds = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof(int);
-		int i, fds[sizeof_fds];
+		int fds[sizeof_fds];
+		unsigned i;

 		memcpy(&fds, CMSG_DATA(cmsg), sizeof(fds));

diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h
index 3b9cda2..c30efb2 100644
--- a/src/lib/torsocks.h
+++ b/src/lib/torsocks.h
@@ -405,7 +405,7 @@ TSOCKS_DECL(listen, LIBC_LISTEN_RET_TYPE, LIBC_LISTEN_SIG)
  */
 enum tsocks_sym_action {
 	TSOCKS_SYM_DO_NOTHING		= 0,
-	TSOCKS_SYM_EXIT_NOT_FOUND	= 1,
+	TSOCKS_SYM_EXIT_NOT_FOUND	= 1
 };

 /* Global configuration. Initialized once in the library constructor. */
diff --git a/tests/test_fd_passing.c b/tests/test_fd_passing.c
index 1803126..f4950bd 100644
--- a/tests/test_fd_passing.c
+++ b/tests/test_fd_passing.c
@@ -324,7 +324,7 @@ static int accept_unix_sock(int sock)
 	return new_fd;
 }

-void *thread_recv(void *data)
+static void *thread_recv(void *data)
 {
 	int ret, new_sock, sock, fds[3] = {-1, -1, -1};
 	char buf[4];
@@ -385,7 +385,7 @@ error:
 	return NULL;
 }

-void *thread_send(void *data)
+static void *thread_send(void *data)
 {
 	int sock, fds[3], pipe_fds[2];
 	ssize_t len;
diff --git a/tests/utils/tap/tap.c b/tests/utils/tap/tap.c
index d52cb03..a785295 100644
--- a/tests/utils/tap/tap.c
+++ b/tests/utils/tap/tap.c
@@ -39,7 +39,7 @@ static unsigned int test_count = 0; /* Number of tests that have been run */
 static unsigned int e_tests = 0; /* Expected number of tests to run */
 static unsigned int failures = 0; /* Number of tests that failed */
 static char *todo_msg = NULL;
-static char *todo_msg_fixed = "libtap malloc issue";
+static const char *todo_msg_fixed = "libtap malloc issue";
 static int todo = 0;
 static int test_died = 0;

@@ -67,8 +67,8 @@ static void _cleanup(void);
  * test_comment -- a comment to print afterwards, may be NULL
  */
 unsigned int
-_gen_result(int ok, const char *func, char *file, unsigned int line,
-	    char *test_name, ...)
+_gen_result(int ok, const char *func, const char *file, unsigned int line,
+	    const char *test_name, ...)
 {
 	va_list ap;
 	char *local_test_name = NULL;
@@ -269,7 +269,7 @@ plan_tests(unsigned int tests)
 }

 unsigned int
-diag(char *fmt, ...)
+diag(const char *fmt, ...)
 {
 	va_list ap;

@@ -293,7 +293,7 @@ _expected_tests(unsigned int tests)
 }

 int
-skip(unsigned int n, char *fmt, ...)
+skip(unsigned int n, const char *fmt, ...)
 {
 	va_list ap;
 	char *skip_msg = NULL;
@@ -321,7 +321,7 @@ skip(unsigned int n, char *fmt, ...)
 }

 void
-todo_start(char *fmt, ...)
+todo_start(const char *fmt, ...)
 {
 	va_list ap;

diff --git a/tests/utils/tap/tap.h b/tests/utils/tap/tap.h
index 0f05943..ddf7240 100644
--- a/tests/utils/tap/tap.h
+++ b/tests/utils/tap/tap.h
@@ -73,17 +73,17 @@

 #define skip_end() } while(0);

-unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...);
+unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...);

 int plan_no_plan(void);
 int plan_skip_all(char *);
 int plan_tests(unsigned int);

-unsigned int diag(char *, ...);
+unsigned int diag(const char *, ...);

-int skip(unsigned int, char *, ...);
+int skip(unsigned int, const char *, ...);

-void todo_start(char *, ...);
+void todo_start(const char *, ...);
 void todo_end(void);

 int exit_status(void);
--
2.1.4

Attachment: signature.asc
Description: This is a digitally signed message part.

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