Misc fixes noticed by "sparse" or by running gcc with additional
authorDan Winship <danw@src.gnome.org>
Sat, 5 Apr 2008 13:56:22 +0000 (13:56 +0000)
committerDan Winship <danw@src.gnome.org>
Sat, 5 Apr 2008 13:56:22 +0000 (13:56 +0000)
-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

svn path=/trunk/; revision=1123

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

index 5f36815..5da2a49 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,41 @@
 2008-04-05  Dan Winship  <danw@gnome.org>
 
+       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
+
+2008-04-05  Dan Winship  <danw@gnome.org>
+
        * libsoup/soup-method.c: Explicitly assign each of the variables
        to NULL, because that apparently causes the OS X linker to treat
        them differently than if they are left implicitly NULL. #522957.
index 6e4d3dc..ffbae60 100644 (file)
@@ -228,7 +228,7 @@ ntlm_authorize_post (SoupMessage *msg, gpointer user_data)
        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)
index 014cff6..340faa8 100644 (file)
@@ -335,7 +335,7 @@ soup_gnutls_get_flags (GIOChannel *channel)
        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,
index 36ccf17..5091fe2 100644 (file)
@@ -640,7 +640,7 @@ soup_uri_encode (const char *part, const char *escape_extra)
 #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 @@ soup_uri_decode (const char *part)
        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;
index 3cb32ef..c16e45d 100644 (file)
@@ -272,7 +272,7 @@ soup_xmlrpc_build_method_response (GValue *value)
        node = xmlNewChild (node, NULL, (const xmlChar *)"param", NULL);
        if (!insert_value (node, value)) {
                xmlFreeDoc (doc);
-               return FALSE;
+               return NULL;
        }
 
        xmlDocDumpMemory (doc, &xmlbody, &len);
index 3d1066d..fec3179 100644 (file)
@@ -39,7 +39,7 @@ gboolean     soup_xmlrpc_extract_method_call     (const char   *method_call,
 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,
                                                  ...);
index 523cdef..08dfda3 100644 (file)
@@ -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 @@ typedef struct {
        guint final_status;
 } SoupAuthTest;
 
-SoupAuthTest tests[] = {
+static SoupAuthTest tests[] = {
        { "No auth available, should fail",
          "Basic/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED },
 
@@ -152,7 +152,7 @@ SoupAuthTest tests[] = {
        { "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 @@ main (int argc, char **argv)
 {
        SoupSession *session;
        SoupMessage *msg;
-       char *base_uri, *uri, *expected;
+       const char *base_uri;
+       char *uri, *expected;
        gboolean authenticated;
        int i;
 
index 6bdd909..53a50d2 100644 (file)
@@ -138,7 +138,7 @@ do_request_test (SoupSession *session, SoupURI *base_uri)
        }
        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++;
        }
 
index fe1b1ba..c226051 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "test-utils.h"
 
-char *base_uri;
+static char *base_uri;
 
 typedef struct {
        SoupServer *server;
@@ -97,8 +97,8 @@ server_callback (SoupServer *server, SoupMessage *msg,
 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)
index ee5e18e..001b852 100644 (file)
 
 #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 @@ do_message (const char *path, gboolean long_body,
 {
        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 @@ do_message (const char *path, gboolean long_body,
        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++;
index c6cd9d9..ae49a24 100644 (file)
 #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)
index a6c3bc7..19021e4 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <libsoup/soup.h>
 
-GMainLoop *loop;
+static GMainLoop *loop;
 
 static void
 print_value (GValue *value)
index 237c4d1..73ddc54 100644 (file)
@@ -13,12 +13,12 @@ typedef struct {
        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 @@ struct RequestTest {
 };
 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 @@ struct ResponseTest {
 };
 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 @@ do_qvalue_tests (void)
                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 @@ do_qvalue_tests (void)
                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;
index f1f75f3..4eec507 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "test-utils.h"
 
-GHashTable *connections;
-
 typedef enum {
        NTLM_UNAUTHENTICATED,
        NTLM_RECEIVED_REQUEST,
index 5d238c8..e4e9581 100644 (file)
@@ -16,14 +16,14 @@ typedef struct {
        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"
index e84eb08..a6c5413 100644 (file)
@@ -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 @@ int
 main (int argc, char **argv)
 {
        SoupSession *session;
-       char *base_uri;
+       const char *base_uri;
 
        test_init (argc, argv, NULL);
        apache_init ();
index 255cd4d..40e21ef 100644 (file)
 
 #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 @@ do_query_tests (const char *uri)
        }
 }
 
-GThread *server_thread;
-
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
@@ -178,7 +174,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
        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,
index d61a3ba..904036f 100644 (file)
 
 #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 @@ do_redirect_tests (SoupURI *base_uri)
        g_object_unref (session);
 }
 
-GThread *server_thread;
-
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
@@ -234,7 +230,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
        }
 }
 
-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,
index 39363a5..af4ec61 100644 (file)
@@ -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 @@ request_started_callback (SoupServer *server, SoupMessage *msg,
                          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,
index fc50063..b8cd164 100644 (file)
@@ -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)
index 92e9902..8dda736 100644 (file)
@@ -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 @@ server_write (gnutls_session_t session, char *buf, int bufsize)
        }
 }
 
-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 @@ start_writing (gpointer user_data)
        return FALSE;
 }
 
-int debug;
-
 static void
 debug_log (int level, const char *str)
 {
@@ -214,7 +212,7 @@ debug_log (int level, const char *str)
 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];
index 3c1005b..faab14a 100644 (file)
 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,
index fa0dc13..535172f 100644 (file)
@@ -8,7 +8,7 @@ void test_init    (int argc, char **argv, GOptionEntry *entries);
 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);
index c189823..52d5271 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "test-utils.h"
 
-struct {
+static struct {
        const char *uri_string, *result;
 } abs_tests[] = {
        { "foo:", "foo:" },
@@ -59,11 +59,11 @@ struct {
        { "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 @@ struct {
         */
        { "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 @@ struct {
        { "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,
index 53f6b6b..b773549 100644 (file)
@@ -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",