libsoup r1123 - in trunk: . libsoup tests



Author: danw
Date: Sat Apr  5 14:56:22 2008
New Revision: 1123
URL: http://svn.gnome.org/viewvc/libsoup?rev=1123&view=rev

Log:
	Misc fixes noticed by "sparse" or by running gcc with additional
	-W flags

	* libsoup/soup-auth-manager-ntlm.c (ntlm_authorize_post): fix a
	potentially uninitialized variable. (Grumble. gcc needs
	-Wdo-optimization-so-you-can-generate-code-flow-related-warnings-
	but-then-emit-unoptimized-code-for-ease-of-debugging)

	* libsoup/soup-gnutls.c (soup_gnutls_channel_funcs): make this
	static

	* libsoup/soup-uri.c (uri_decoded_copy, uri_normalized_copy): add
	"static". (This doesn't change the generated code; the prototype
	was already declared static and so gcc was treating the function
	as static even though the main declaration *wasn't* declared
	static. I'm not sure if this is a bug in gcc or an oddity of the
	spec, but it's confusing, so...)

	* libsoup/soup-xmlrpc.c (soup_xmlrpc_build_method_response):
	s/FALSE/NULL/

	* libsoup/soup-xmlrpc.h: add G_GNUC_PRINTF to
	soup_xmlrpc_build_format

	* tests/*.c: misc minor fixes, mostly involving missing "const"s
	and "static"s to get better warnings, and then remove some unused
	variables.

	* tests/continue-test.c (do_message): fix a crash when the test
	fails

	* tests/test-utils.h (debug_printf): add G_GNUC_PRINTF to
	prototype


Modified:
   trunk/ChangeLog
   trunk/libsoup/soup-auth-manager-ntlm.c
   trunk/libsoup/soup-gnutls.c
   trunk/libsoup/soup-uri.c
   trunk/libsoup/soup-xmlrpc.c
   trunk/libsoup/soup-xmlrpc.h
   trunk/tests/auth-test.c
   trunk/tests/chunk-test.c
   trunk/tests/context-test.c
   trunk/tests/continue-test.c
   trunk/tests/get.c
   trunk/tests/getbug.c
   trunk/tests/header-parsing.c
   trunk/tests/ntlm-test.c
   trunk/tests/proxy-test.c
   trunk/tests/pull-api.c
   trunk/tests/query-test.c
   trunk/tests/redirect-test.c
   trunk/tests/server-auth-test.c
   trunk/tests/simple-proxy.c
   trunk/tests/ssl-test.c
   trunk/tests/test-utils.c
   trunk/tests/test-utils.h
   trunk/tests/uri-parsing.c
   trunk/tests/xmlrpc-test.c

Modified: trunk/libsoup/soup-auth-manager-ntlm.c
==============================================================================
--- trunk/libsoup/soup-auth-manager-ntlm.c	(original)
+++ trunk/libsoup/soup-auth-manager-ntlm.c	Sat Apr  5 14:56:22 2008
@@ -228,7 +228,7 @@
 	SoupAuthManagerNTLM *ntlm = user_data;
 	SoupNTLMConnection *conn;
 	const char *username = NULL, *password = NULL;
-	char *slash, *domain;
+	char *slash, *domain = NULL;
 
 	conn = get_connection_for_msg (ntlm, msg);
 	if (!conn || !conn->auth)

Modified: trunk/libsoup/soup-gnutls.c
==============================================================================
--- trunk/libsoup/soup-gnutls.c	(original)
+++ trunk/libsoup/soup-gnutls.c	Sat Apr  5 14:56:22 2008
@@ -335,7 +335,7 @@
 	return chan->real_sock->funcs->io_get_flags (channel);
 }
 
-const GIOFuncs soup_gnutls_channel_funcs = {
+static const GIOFuncs soup_gnutls_channel_funcs = {
 	soup_gnutls_read,
 	soup_gnutls_write,
 	soup_gnutls_seek,

Modified: trunk/libsoup/soup-uri.c
==============================================================================
--- trunk/libsoup/soup-uri.c	(original)
+++ trunk/libsoup/soup-uri.c	Sat Apr  5 14:56:22 2008
@@ -640,7 +640,7 @@
 #define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
 #define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
 
-char *
+static char *
 uri_decoded_copy (const char *part, int length)
 {
 	unsigned char *s, *d;
@@ -678,7 +678,7 @@
 	return uri_decoded_copy (part, strlen (part));
 }
 
-char *
+static char *
 uri_normalized_copy (const char *part, int length, const char *unescape_extra)
 {
 	unsigned char *s, *d, c;

Modified: trunk/libsoup/soup-xmlrpc.c
==============================================================================
--- trunk/libsoup/soup-xmlrpc.c	(original)
+++ trunk/libsoup/soup-xmlrpc.c	Sat Apr  5 14:56:22 2008
@@ -272,7 +272,7 @@
 	node = xmlNewChild (node, NULL, (const xmlChar *)"param", NULL);
 	if (!insert_value (node, value)) {
 		xmlFreeDoc (doc);
-		return FALSE;
+		return NULL;
 	}
 
 	xmlDocDumpMemory (doc, &xmlbody, &len);

Modified: trunk/libsoup/soup-xmlrpc.h
==============================================================================
--- trunk/libsoup/soup-xmlrpc.h	(original)
+++ trunk/libsoup/soup-xmlrpc.h	Sat Apr  5 14:56:22 2008
@@ -39,7 +39,7 @@
 char        *soup_xmlrpc_build_method_response   (GValue       *value);
 char        *soup_xmlrpc_build_fault             (int           fault_code,
 						  const char   *fault_format,
-						  ...);
+						  ...) G_GNUC_PRINTF (2, 3);
 void         soup_xmlrpc_set_response            (SoupMessage  *msg,
 						  GType         type,
 						  ...);

Modified: trunk/tests/auth-test.c
==============================================================================
--- trunk/tests/auth-test.c	(original)
+++ trunk/tests/auth-test.c	Sat Apr  5 14:56:22 2008
@@ -14,7 +14,7 @@
 
 #include "test-utils.h"
 
-GMainLoop *loop;
+static GMainLoop *loop;
 
 typedef struct {
 	/* Explanation of what you should see */
@@ -43,7 +43,7 @@
 	guint final_status;
 } SoupAuthTest;
 
-SoupAuthTest tests[] = {
+static SoupAuthTest tests[] = {
 	{ "No auth available, should fail",
 	  "Basic/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED },
 
@@ -152,7 +152,7 @@
 	{ "Make sure we've forgotten it",
 	  "Digest/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED }
 };
-int ntests = sizeof (tests) / sizeof (tests[0]);
+static int ntests = sizeof (tests) / sizeof (tests[0]);
 
 static const char *auths[] = {
 	"no password", "password 1",
@@ -550,7 +550,8 @@
 {
 	SoupSession *session;
 	SoupMessage *msg;
-	char *base_uri, *uri, *expected;
+	const char *base_uri;
+	char *uri, *expected;
 	gboolean authenticated;
 	int i;
 

Modified: trunk/tests/chunk-test.c
==============================================================================
--- trunk/tests/chunk-test.c	(original)
+++ trunk/tests/chunk-test.c	Sat Apr  5 14:56:22 2008
@@ -138,7 +138,7 @@
 	}
 	if (msg->request_body->length != length || length != ptd.nwrote) {
 		debug_printf (1, "  sent length mismatch: %d vs %d vs %d\n",
-			      msg->request_body->length, length, ptd.nwrote);
+			      (int)msg->request_body->length, length, ptd.nwrote);
 		errors++;
 	}
 

Modified: trunk/tests/context-test.c
==============================================================================
--- trunk/tests/context-test.c	(original)
+++ trunk/tests/context-test.c	Sat Apr  5 14:56:22 2008
@@ -23,7 +23,7 @@
 
 #include "test-utils.h"
 
-char *base_uri;
+static char *base_uri;
 
 typedef struct {
 	SoupServer *server;
@@ -97,8 +97,8 @@
 static gboolean idle_start_test1_thread (gpointer loop);
 static gpointer test1_thread (gpointer user_data);
 
-GCond *test1_cond;
-GMutex *test1_mutex;
+static GCond *test1_cond;
+static GMutex *test1_mutex;
 
 static void
 do_test1 (void)

Modified: trunk/tests/continue-test.c
==============================================================================
--- trunk/tests/continue-test.c	(original)
+++ trunk/tests/continue-test.c	Sat Apr  5 14:56:22 2008
@@ -19,11 +19,11 @@
 
 #define MAX_POST_LENGTH (sizeof (SHORT_BODY))
 
-int port;
-GSList *events;
+static int port;
+static GSList *events;
 
 static void
-event (SoupMessage *msg, char *side, char *message)
+event (SoupMessage *msg, const char *side, const char *message)
 {
 	char *data = g_strdup_printf ("%s-%s", side, message);
 	gboolean record_status =
@@ -62,7 +62,8 @@
 {
 	SoupSession *session;
 	SoupMessage *msg;
-	char *uri, *body;
+	const char *body;
+	char *uri;
 	va_list ap;
 	const char *expected_event;
 	char *actual_event;
@@ -115,7 +116,7 @@
 	while ((expected_event = va_arg (ap, const char *))) {
 
 		if (!events) {
-			actual_event = "";
+			actual_event = g_strdup ("");
 			debug_printf (1, "  Expected '%s', got end of list\n",
 				      expected_event);
 			errors++;

Modified: trunk/tests/get.c
==============================================================================
--- trunk/tests/get.c	(original)
+++ trunk/tests/get.c	Sat Apr  5 14:56:22 2008
@@ -19,14 +19,13 @@
 #define mkdir(path, mode) _mkdir (path)
 #endif
 
-SoupSession *session;
-GMainLoop *loop;
-gboolean recurse = FALSE, debug = FALSE;
-const char *method;
-char *base;
-SoupURI *base_uri;
-int pending;
-GHashTable *fetched_urls;
+static SoupSession *session;
+static GMainLoop *loop;
+static gboolean recurse = FALSE, debug = FALSE;
+static const char *method;
+static char *base;
+static SoupURI *base_uri;
+static GHashTable *fetched_urls;
 
 static GPtrArray *
 find_hrefs (SoupURI *base, const char *body, int length)

Modified: trunk/tests/getbug.c
==============================================================================
--- trunk/tests/getbug.c	(original)
+++ trunk/tests/getbug.c	Sat Apr  5 14:56:22 2008
@@ -14,7 +14,7 @@
 
 #include <libsoup/soup.h>
 
-GMainLoop *loop;
+static GMainLoop *loop;
 
 static void
 print_value (GValue *value)

Modified: trunk/tests/header-parsing.c
==============================================================================
--- trunk/tests/header-parsing.c	(original)
+++ trunk/tests/header-parsing.c	Sat Apr  5 14:56:22 2008
@@ -13,12 +13,12 @@
 	char *name, *value;
 } Header;
 
-struct RequestTest {
-	char *description;
-	char *request;
+static struct RequestTest {
+	const char *description;
+	const char *request;
 	int length;
 	guint status;
-	char *method, *path;
+	const char *method, *path;
 	SoupHTTPVersion version;
 	Header headers[4];
 } reqtests[] = {
@@ -347,13 +347,13 @@
 };
 static const int num_reqtests = G_N_ELEMENTS (reqtests);
 
-struct ResponseTest {
-	char *description;
-	char *response;
+static struct ResponseTest {
+	const char *description;
+	const char *response;
 	int length;
 	SoupHTTPVersion version;
 	guint status_code;
-	char *reason_phrase;
+	const char *reason_phrase;
 	Header headers[4];
 } resptests[] = {
 	/***********************/
@@ -548,7 +548,7 @@
 };
 static const int num_resptests = G_N_ELEMENTS (resptests);
 
-struct QValueTest {
+static struct QValueTest {
 	char *header_value;
 	char *acceptable[7];
 	char *unacceptable[2];
@@ -778,7 +778,7 @@
 		wrong = FALSE;
 		if (acceptable) {
 			for (iter = acceptable, j = 0; iter; iter = iter->next, j++) {
-				debug_printf (1, "%s ", iter->data);
+				debug_printf (1, "%s ", (char *)iter->data);
 				if (!qvaluetests[i].acceptable[j] ||
 				    strcmp (iter->data, qvaluetests[i].acceptable[j]) != 0)
 					wrong = TRUE;
@@ -799,7 +799,7 @@
 		wrong = FALSE;
 		if (unacceptable) {
 			for (iter = unacceptable, j = 0; iter; iter = iter->next, j++) {
-				debug_printf (1, "%s ", iter->data);
+				debug_printf (1, "%s ", (char *)iter->data);
 				if (!qvaluetests[i].unacceptable[j] ||
 				    strcmp (iter->data, qvaluetests[i].unacceptable[j]) != 0)
 					wrong = TRUE;

Modified: trunk/tests/ntlm-test.c
==============================================================================
--- trunk/tests/ntlm-test.c	(original)
+++ trunk/tests/ntlm-test.c	Sat Apr  5 14:56:22 2008
@@ -28,8 +28,6 @@
 
 #include "test-utils.h"
 
-GHashTable *connections;
-
 typedef enum {
 	NTLM_UNAUTHENTICATED,
 	NTLM_RECEIVED_REQUEST,

Modified: trunk/tests/proxy-test.c
==============================================================================
--- trunk/tests/proxy-test.c	(original)
+++ trunk/tests/proxy-test.c	Sat Apr  5 14:56:22 2008
@@ -16,14 +16,14 @@
 	const guint final_status;
 } SoupProxyTest;
 
-SoupProxyTest tests[] = {
+static SoupProxyTest tests[] = {
 	{ "GET -> 200", "", SOUP_STATUS_OK },
 	{ "GET -> 404", "/not-found", SOUP_STATUS_NOT_FOUND },
 	{ "GET -> 401 -> 200", "/Basic/realm1/", SOUP_STATUS_OK },
 	{ "GET -> 401 -> 401", "/Basic/realm2/", SOUP_STATUS_UNAUTHORIZED },
 	{ "GET -> 403", "http://no-proxy.example.com/";, SOUP_STATUS_FORBIDDEN },
 };
-int ntests = sizeof (tests) / sizeof (tests[0]);
+static int ntests = sizeof (tests) / sizeof (tests[0]);
 
 #define HTTP_SERVER    "http://127.0.0.1:47524";
 #define HTTPS_SERVER   "https://127.0.0.1:47525";

Modified: trunk/tests/pull-api.c
==============================================================================
--- trunk/tests/pull-api.c	(original)
+++ trunk/tests/pull-api.c	Sat Apr  5 14:56:22 2008
@@ -13,7 +13,7 @@
 
 #include "test-utils.h"
 
-SoupBuffer *correct_response;
+static SoupBuffer *correct_response;
 
 static void
 authenticate (SoupSession *session, SoupMessage *msg,
@@ -490,7 +490,7 @@
 main (int argc, char **argv)
 {
 	SoupSession *session;
-	char *base_uri;
+	const char *base_uri;
 
 	test_init (argc, argv, NULL);
 	apache_init ();

Modified: trunk/tests/query-test.c
==============================================================================
--- trunk/tests/query-test.c	(original)
+++ trunk/tests/query-test.c	Sat Apr  5 14:56:22 2008
@@ -24,11 +24,9 @@
 
 #include "test-utils.h"
 
-GMainLoop *loop;
-
-struct {
-	char *title, *name;
-	char *result;
+static struct {
+	const char *title, *name;
+	const char *result;
 } tests[] = {
 	/* Both fields must be filled in */
 	{ NULL, "Name", "" },
@@ -122,8 +120,6 @@
 	}
 }
 
-GThread *server_thread;
-
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
 		 const char *path, GHashTable *query,
@@ -178,7 +174,7 @@
 	soup_message_set_status (msg, SOUP_STATUS_OK);
 }
 
-gboolean run_tests = TRUE;
+static gboolean run_tests = TRUE;
 
 static GOptionEntry no_test_entry[] = {
         { "no-tests", 'n', G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_REVERSE,

Modified: trunk/tests/redirect-test.c
==============================================================================
--- trunk/tests/redirect-test.c	(original)
+++ trunk/tests/redirect-test.c	Sat Apr  5 14:56:22 2008
@@ -14,15 +14,13 @@
 
 #include "test-utils.h"
 
-GMainLoop *loop;
-
 typedef struct {
 	const char *method;
 	const char *path;
 	guint status_code;
 } TestRequest;
 
-struct {
+static struct {
 	TestRequest requests[3];
 } tests[] = {
 	/* A redirecty response to a GET should cause a redirect */
@@ -177,8 +175,6 @@
 	g_object_unref (session);
 }
 
-GThread *server_thread;
-
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
 		 const char *path, GHashTable *query,
@@ -234,7 +230,7 @@
 	}
 }
 
-gboolean run_tests = TRUE;
+static gboolean run_tests = TRUE;
 
 static GOptionEntry no_test_entry[] = {
         { "no-tests", 'n', G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_REVERSE,

Modified: trunk/tests/server-auth-test.c
==============================================================================
--- trunk/tests/server-auth-test.c	(original)
+++ trunk/tests/server-auth-test.c	Sat Apr  5 14:56:22 2008
@@ -25,9 +25,7 @@
 
 #include "test-utils.h"
 
-GMainLoop *loop;
-
-struct {
+static struct {
 	gboolean client_sent_basic, client_sent_digest;
 	gboolean server_requested_basic, server_requested_digest;
 	gboolean succeeded;
@@ -319,7 +317,7 @@
 			  G_CALLBACK (wrote_headers_callback), NULL);
 }
 
-gboolean run_tests = TRUE;
+static gboolean run_tests = TRUE;
 
 static GOptionEntry no_test_entry[] = {
         { "no-tests", 'n', G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_REVERSE,

Modified: trunk/tests/simple-proxy.c
==============================================================================
--- trunk/tests/simple-proxy.c	(original)
+++ trunk/tests/simple-proxy.c	Sat Apr  5 14:56:22 2008
@@ -23,8 +23,8 @@
  * RFC 2616. But it does work for basic stuff.
  */
 
-SoupSession *session;
-SoupServer *server;
+static SoupSession *session;
+static SoupServer *server;
 
 static void
 copy_header (const char *name, const char *value, gpointer dest_headers)

Modified: trunk/tests/ssl-test.c
==============================================================================
--- trunk/tests/ssl-test.c	(original)
+++ trunk/tests/ssl-test.c	Sat Apr  5 14:56:22 2008
@@ -14,8 +14,8 @@
 #define BUFSIZE 1024
 #define DH_BITS 1024
 
-GMainLoop *loop;
-gnutls_dh_params_t dh_params;
+static GMainLoop *loop;
+static gnutls_dh_params_t dh_params;
 
 /* SERVER */
 
@@ -64,8 +64,8 @@
 	}
 }
 
-const char *ssl_cert_file = SRCDIR "/test-cert.pem";
-const char *ssl_key_file = SRCDIR "/test-key.pem";
+static const char *ssl_cert_file = SRCDIR "/test-cert.pem";
+static const char *ssl_key_file = SRCDIR "/test-key.pem";
 
 static gpointer
 server_thread (gpointer user_data)
@@ -203,8 +203,6 @@
 	return FALSE;
 }
 
-int debug;
-
 static void
 debug_log (int level, const char *str)
 {
@@ -214,7 +212,7 @@
 int
 main (int argc, char **argv)
 {
-	int opt, listener, sin_len, port, i;
+	int opt, debug = 0, listener, sin_len, port, i;
 	struct sockaddr_in sin;
 	GThread *server;
 	char writebuf[BUFSIZE], readbuf[BUFSIZE];

Modified: trunk/tests/test-utils.c
==============================================================================
--- trunk/tests/test-utils.c	(original)
+++ trunk/tests/test-utils.c	Sat Apr  5 14:56:22 2008
@@ -17,12 +17,13 @@
 static gboolean apache_running;
 #endif
 static SoupServer *test_server;
-GThread *server_thread;
+static GThread *server_thread;
 static void test_server_shutdown (void);
 
 static SoupLogger *logger;
 
-int debug_level, http_debug_level, errors;
+int debug_level, errors;
+static int http_debug_level;
 
 static gboolean
 increment_debug_level (const char *option_name, const char *value,

Modified: trunk/tests/test-utils.h
==============================================================================
--- trunk/tests/test-utils.h	(original)
+++ trunk/tests/test-utils.h	Sat Apr  5 14:56:22 2008
@@ -8,7 +8,7 @@
 void test_cleanup (void);
 
 extern int debug_level, errors;
-void debug_printf (int level, const char *format, ...);
+void debug_printf (int level, const char *format, ...) G_GNUC_PRINTF (2, 3);
 
 #ifdef HAVE_APACHE
 void apache_init    (void);

Modified: trunk/tests/uri-parsing.c
==============================================================================
--- trunk/tests/uri-parsing.c	(original)
+++ trunk/tests/uri-parsing.c	Sat Apr  5 14:56:22 2008
@@ -10,7 +10,7 @@
 
 #include "test-utils.h"
 
-struct {
+static struct {
 	const char *uri_string, *result;
 } abs_tests[] = {
 	{ "foo:", "foo:" },
@@ -59,11 +59,11 @@
 	{ "http://[2010:836B:4179::836B:4179]";,
 	  "http://[2010:836B:4179::836B:4179]/"; }
 };
-int num_abs_tests = G_N_ELEMENTS(abs_tests);
+static int num_abs_tests = G_N_ELEMENTS(abs_tests);
 
 /* From RFC 3986. */
-const char *base = "http://a/b/c/d;p?q";;
-struct {
+static const char *base = "http://a/b/c/d;p?q";;
+static struct {
 	const char *uri_string, *result;
 } rel_tests[] = {
 	{ "g:h", "g:h" },
@@ -116,10 +116,10 @@
 	 */
 	{ "http:g", NULL }
 };
-int num_rel_tests = G_N_ELEMENTS(rel_tests);
+static int num_rel_tests = G_N_ELEMENTS(rel_tests);
 
-struct {
-	char *one, *two;
+static struct {
+	const char *one, *two;
 } eq_tests[] = {
 	{ "example://a/b/c/%7Bfoo%7D", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d" },
 	{ "http://example.com";, "http://example.com/"; },
@@ -128,7 +128,7 @@
 	{ "http://abc.com:80/~smith/home.html";, "http://ABC.com/%7Esmith/home.html"; },
 	{ "http://abc.com:80/~smith/home.html";, "http://ABC.com:/%7esmith/home.html"; },
 };
-int num_eq_tests = G_N_ELEMENTS(eq_tests);
+static int num_eq_tests = G_N_ELEMENTS(eq_tests);
 
 static gboolean
 do_uri (SoupURI *base_uri, const char *base_str,

Modified: trunk/tests/xmlrpc-test.c
==============================================================================
--- trunk/tests/xmlrpc-test.c	(original)
+++ trunk/tests/xmlrpc-test.c	Sat Apr  5 14:56:22 2008
@@ -12,9 +12,9 @@
 
 #include "test-utils.h"
 
-SoupSession *session;
+static SoupSession *session;
 static const char *default_uri = "http://localhost:47524/xmlrpc-server.php";;
-const char *uri = NULL;
+static const char *uri = NULL;
 
 static const char *const value_type[] = {
 	"BAD",



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