changeset 1134:b08b73591d2c

Switch to gcc -Wall
author Adam Chlipala <adamc@hcoop.net>
date Thu, 28 Jan 2010 13:32:26 -0500
parents 482815817e99
children 0aa2758cca32
files Makefile.am Makefile.in src/c/Makefile.am src/c/Makefile.in src/c/cgi.c src/c/fastcgi.c src/c/http.c src/c/request.c src/c/urweb.c
diffstat 9 files changed, 50 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu Jan 28 10:48:49 2010 -0500
+++ b/Makefile.am	Thu Jan 28 13:32:26 2010 -0500
@@ -69,7 +69,7 @@
 	cp include/*.h $(INCLUDE)/
 	mkdir -p $(SITELISP)
 	cp src/elisp/*.el $(SITELISP)/
-	ldconfig
+	-ldconfig
 
 package:
 	hg archive -t tgz -X tests /tmp/urweb.tgz
--- a/Makefile.in	Thu Jan 28 10:48:49 2010 -0500
+++ b/Makefile.in	Thu Jan 28 13:32:26 2010 -0500
@@ -758,7 +758,7 @@
 	cp include/*.h $(INCLUDE)/
 	mkdir -p $(SITELISP)
 	cp src/elisp/*.el $(SITELISP)/
-	ldconfig
+	-ldconfig
 
 package:
 	hg archive -t tgz -X tests /tmp/urweb.tgz
--- a/src/c/Makefile.am	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/Makefile.am	Thu Jan 28 13:32:26 2010 -0500
@@ -6,3 +6,4 @@
 liburweb_fastcgi_la_SOURCES = fastcgi.c
 
 AM_CPPFLAGS = -I../../include
+AM_CFLAGS = -Wimplicit -Wall -Werror
--- a/src/c/Makefile.in	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/Makefile.in	Thu Jan 28 13:32:26 2010 -0500
@@ -221,6 +221,7 @@
 liburweb_cgi_la_SOURCES = cgi.c
 liburweb_fastcgi_la_SOURCES = fastcgi.c
 AM_CPPFLAGS = -I../../include
+AM_CFLAGS = -Wimplicit -Wall -Werror
 all: all-am
 
 .SUFFIXES:
--- a/src/c/cgi.c	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/cgi.c	Thu Jan 28 13:32:26 2010 -0500
@@ -28,7 +28,7 @@
     *s++ = *h == '-' ? '_' : toupper(*h);
   *s = 0;
 
-  if (r = getenv(uppercased))
+  if ((r = getenv(uppercased)))
     return r;
   else if (!strcasecmp(saved_h, "Content-length")
            || !strcasecmp(saved_h, "Content-type"))
--- a/src/c/fastcgi.c	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/fastcgi.c	Thu Jan 28 13:32:26 2010 -0500
@@ -139,7 +139,7 @@
   va_list ap;
   va_start(ap, fmt);
 
-  len = vsnprintf(o->r.contentData, 65535, fmt, ap);
+  len = vsnprintf((char *)o->r.contentData, 65535, fmt, ap);
   if (len < 0)
     fprintf(stderr, "vsnprintf() failed in write_stderr().\n");
   else if (fastcgi_send(o, FCGI_STDERR, len))
@@ -157,7 +157,7 @@
   va_start(ap, fmt);
 
   if (o) {
-    int len = vsnprintf(o->r.contentData, 65535, fmt, ap);
+    int len = vsnprintf((char *)o->r.contentData, 65535, fmt, ap);
     if (len < 0)
       fprintf(stderr, "vsnprintf() failed in log_error().\n");
     else if (fastcgi_send(o, FCGI_STDERR, len))
@@ -191,7 +191,7 @@
 static char *get_header(void *data, const char *h) {
   headers *hs = (headers *)data;
   size_t len = strlen(h);
-  char *s, *r;
+  char *s;
   const char *saved_h = h;
 
   if (len > hs->uppercased_len) {
@@ -206,7 +206,7 @@
 
   if (!strcasecmp(saved_h, "Content-length")
       || !strcasecmp(saved_h, "Content-type")) {
-    if (s = search_nvps(hs->nvps, hs->uppercased + 5))
+    if ((s = search_nvps(hs->nvps, hs->uppercased + 5)))
       return s;
   }
   
@@ -300,7 +300,6 @@
 }
 
 static void *worker(void *data) {
-  int me = *(int *)data;
   FCGI_Input *in = fastcgi_input();
   FCGI_Output *out = fastcgi_output();
   uw_context ctx = uw_request_new_context(&uw_application, out, log_error, log_debug);
@@ -310,7 +309,6 @@
   char *body = malloc(0);
   size_t path_size = 0;
   char *path_buf = malloc(0);
-  int tries = 0;
 
   hs.uppercased = malloc(0);
   hs.uppercased_len = 0;
@@ -385,7 +383,7 @@
 
     hs.nvps[used_nvps].name[0] = 0;
 
-    if (s = get_header(&hs, "Content-Length")) {
+    if ((s = get_header(&hs, "Content-Length"))) {
       body_len = atoi(s);
       if (body_len < 0) {
         write_stderr(out, "Invalid Content-Length\n");
@@ -400,7 +398,6 @@
     }
 
     for (body_read = 0; body_read < body_len; ) {
-      char *buf;
       int this_len;
 
       if (!(r = fastcgi_recv(in))) {
@@ -441,7 +438,7 @@
       goto done;
     }
 
-    if (path_info = search_nvps(hs.nvps, "PATH_INFO")) {
+    if ((path_info = search_nvps(hs.nvps, "PATH_INFO"))) {
       int len1 = strlen(path), len2 = strlen(path_info);
       int len = len1 + len2 + 1;
 
@@ -497,7 +494,7 @@
 int main(int argc, char *argv[]) {
   // The skeleton for this function comes from Beej's sockets tutorial.
   struct sockaddr_in their_addr; // connector's address information
-  int sin_size, yes = 1;
+  socklen_t sin_size;
   int nthreads = 1, i, *names, opt;
   char *fwsa = getenv("FCGI_WEB_SERVER_ADDRS"), *nthreads_s = getenv("URWEB_NUM_THREADS");
  
@@ -549,7 +546,6 @@
 
   {
     pthread_t thread;
-    int name;
 
     if (pthread_create(&thread, NULL, client_pruner, &ls)) {
       fprintf(stderr, "Error creating pruner thread\n");
@@ -583,7 +579,7 @@
         return 1;
       }
 
-      for (ips = fwsa; sep = strchr(ips, ','); ips = sep+1) {
+      for (ips = fwsa; (sep = strchr(ips, ',')); ips = sep+1) {
         if (!strncmp(ips, host, sep - ips)) {
           matched = 1;
           break;
--- a/src/c/http.c	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/http.c	Thu Jan 28 13:32:26 2010 -0500
@@ -25,7 +25,7 @@
   int len = strlen(h);
   char *p;
 
-  while (p = strchr(s, ':')) {
+  while ((p = strchr(s, ':'))) {
     if (p - s == len && !strncasecmp(s, h, len)) {
       return p + 2;
     } else {
@@ -169,10 +169,10 @@
         }
         path = s;
 
-        if (s = strchr(path, ' '))
+        if ((s = strchr(path, ' ')))
           *s = 0;
 
-        if (s = strchr(path, '?')) {
+        if ((s = strchr(path, '?'))) {
           *s = 0;
           query_string = s+1;
         }
@@ -180,7 +180,7 @@
           query_string = NULL;
 
         s = headers;
-        while (s2 = strchr(s, '\r')) {
+        while ((s2 = strchr(s, '\r'))) {
           s = s2;
 
           if (s[1] == 0)
@@ -228,8 +228,8 @@
   int sockfd;  // listen on sock_fd
   struct sockaddr_in my_addr;
   struct sockaddr_in their_addr; // connector's address information
-  int sin_size, yes = 1;
-  int uw_port = 8080, nthreads = 1, i, *names, opt;
+  socklen_t sin_size;
+  int yes = 1, uw_port = 8080, nthreads = 1, i, *names, opt;
  
   signal(SIGINT, sigint);
   signal(SIGPIPE, SIG_IGN); 
@@ -306,7 +306,6 @@
 
   {
     pthread_t thread;
-    int name;
 
     if (pthread_create(&thread, NULL, client_pruner, &ls)) {
       fprintf(stderr, "Error creating pruner thread\n");
--- a/src/c/request.c	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/request.c	Thu Jan 28 13:32:26 2010 -0500
@@ -122,11 +122,10 @@
                           int (*send)(int sockfd, const void *buf, size_t len),
                           int (*close)(int fd)) {
   int retries_left = MAX_RETRIES;
-  char *s;
   failure_kind fk;
-  int is_post = 0, do_normal_send = 1;
+  int is_post = 0;
   char *boundary = NULL;
-  size_t boundary_len;
+  size_t boundary_len = 0;
   char *inputs;
   const char *prefix = uw_get_url_prefix(ctx);
 
@@ -226,7 +225,7 @@
       after_sub_headers[2] = 0;
       after_sub_headers += 4;
 
-      for (header = part; after_header = strstr(header, "\r\n"); header = after_header + 2) {
+      for (header = part; (after_header = strstr(header, "\r\n")); header = after_header + 2) {
         char *colon, *after_colon;
 
         *after_header = 0;
@@ -246,7 +245,7 @@
             return FAILED;
           }
 
-          for (colon += 11; after_colon = strchr(colon, '='); colon = after_colon) {
+          for (colon += 11; (after_colon = strchr(colon, '=')); colon = after_colon) {
             char *data;
             after_colon[0] = 0;
             if (after_colon[1] != '"') {
@@ -304,12 +303,12 @@
 
       while (*inputs) {
         name = inputs;
-        if (inputs = strchr(inputs, '&'))
+        if ((inputs = strchr(inputs, '&')))
           *inputs++ = 0;
         else
           inputs = strchr(name, 0);
 
-        if (value = strchr(name, '=')) {
+        if ((value = strchr(name, '='))) {
           *value++ = 0;
           if (uw_set_input(ctx, name, value)) {
             log_error(logger_data, "%s\n", uw_error_message(ctx));
--- a/src/c/urweb.c	Thu Jan 28 10:48:49 2010 -0500
+++ b/src/c/urweb.c	Thu Jan 28 13:32:26 2010 -0500
@@ -83,11 +83,12 @@
       next = 1;
     for (; next < desired; next *= 2);
 
-    if (next > b->max)
+    if (next > b->max) {
       if (desired <= b->max)
         next = desired;
       else
         return 1;
+    }
 
     new_heap = realloc(b->start, next);
     b->front = new_heap + (b->front - b->start);
@@ -519,6 +520,8 @@
     ctx->inputs = realloc(ctx->inputs, ctx->sz_inputs * sizeof(input));
     memset(ctx->inputs, 0, ctx->sz_inputs * sizeof(input));
   }
+
+  return 0;
 }
 
 void uw_set_client_data(uw_context ctx, void *data) {
@@ -557,8 +560,6 @@
 }
 
 void uw_reset_keep_error_message(uw_context ctx) {
-  size_t i;
-
   buf_reset(&ctx->outHeaders);
   buf_reset(&ctx->script);
   ctx->script.start[0] = 0;
@@ -643,11 +644,12 @@
     else
       newLen = len * 2;
 
-    if (newLen > uw_cleanup_max)
+    if (newLen > uw_cleanup_max) {
       if (len+1 <= uw_cleanup_max)
         newLen = uw_cleanup_max;
       else
         uw_error(ctx, FATAL, "Exceeded limit on number of cleanup handlers");
+    }
 
     ctx->cleanup = realloc(ctx->cleanup, newLen * sizeof(cleanup));
     ctx->cleanup_front = ctx->cleanup + len;
@@ -764,6 +766,9 @@
     adjust_pointer(&x->data.entry.fields, old_start, new_start, len);
     adjust_pointer(&x->data.entry.next, old_start, new_start, len);
     adjust_pointer(&x->data.entry.parent, old_start, new_start, len);
+    break;
+  default:
+    break;
   }  
 }
 
@@ -778,7 +783,6 @@
       uw_error(ctx, FATAL, "Exceeded limit on number of subinputs");
 
     input *new_subinputs = realloc(ctx->subinputs, sizeof(input) * (ctx->used_subinputs + len));
-    size_t offset = new_subinputs - ctx->subinputs;
 
     if (ctx->subinputs != new_subinputs) {
       for (i = 0; i < ctx->used_subinputs; ++i)
@@ -979,34 +983,6 @@
 
 void *uw_malloc(uw_context ctx, size_t len);
 
-static void parents(input *inp) {
-  printf("Stack: %p\n", inp);
-  while (inp) {
-    switch (inp->kind) {
-    case NORMAL:
-      printf("Normal(%p)\n", inp);
-      break;
-    case FIL:
-      printf("File(%p)\n", inp);
-      break;
-    case SUBFORM:
-      printf("Subform; fields = %p\n", inp->data.subform.fields);
-      inp = inp->data.subform.parent;
-      break;
-    case SUBFORMS:
-      printf("Subforms; entries = %p\n", inp->data.subforms.entries);
-      inp = inp->data.subforms.parent;
-      break;
-    case ENTRY:
-      printf("Entry; fields = %p; next = %p\n", inp->data.entry.fields, inp->data.entry.next);
-      inp = inp->data.entry.parent;
-      break;
-    default:
-      inp = NULL;
-    }
-  }
-}
-
 uw_Basis_file uw_get_file_input(uw_context ctx, int n) {
   if (n < 0)
     uw_error(ctx, FATAL, "Negative file input index %d", n);
@@ -1159,11 +1135,12 @@
       next = 1;
     for (; next < desired; next *= 2);
 
-    if (next > b->max)
+    if (next > b->max) {
       if (desired <= b->max)
         next = desired;
       else
         uw_error(ctx, FATAL, "Memory limit exceeded (%s)", kind);
+    }
 
     new_heap = realloc(b->start, next);
     b->front = new_heap + (b->front - b->start);
@@ -1222,10 +1199,10 @@
 }
 
 void uw_memstats(uw_context ctx) {
-  printf("Headers: %d/%d\n", buf_used(&ctx->outHeaders), buf_avail(&ctx->outHeaders));
-  printf("Script: %d/%d\n", buf_used(&ctx->script), buf_avail(&ctx->script));
-  printf("Page: %d/%d\n", buf_used(&ctx->page), buf_avail(&ctx->page));
-  printf("Heap: %d/%d\n", buf_used(&ctx->heap), buf_avail(&ctx->heap));
+  printf("Headers: %lu/%lu\n", (unsigned long)buf_used(&ctx->outHeaders), (unsigned long)buf_avail(&ctx->outHeaders));
+  printf("Script: %lu/%lu\n", (unsigned long)buf_used(&ctx->script), (unsigned long)buf_avail(&ctx->script));
+  printf("Page: %lu/%lu\n", (unsigned long)buf_used(&ctx->page), (unsigned long)buf_avail(&ctx->page));
+  printf("Heap: %lu/%lu\n", (unsigned long)buf_used(&ctx->heap), (unsigned long)buf_avail(&ctx->heap));
 }
 
 int uw_send(uw_context ctx, int sock) {
@@ -1547,10 +1524,6 @@
   return result;
 }
 
-static int isCont(unsigned char ch) {
-  return ch / 64 == 2;
-}
-
 char *uw_Basis_attrifyString(uw_context ctx, uw_Basis_string s) {
   int len = strlen(s);
   char *result, *p;
@@ -1893,8 +1866,8 @@
 
 uw_Basis_string uw_Basis_unurlifyString(uw_context ctx, char **s) {
   char *new_s = uw_unurlify_advance(*s);
-  char *r, *s1, *s2;
-  int len, n;
+  char *r;
+  int len;
 
   len = strlen(*s);
   uw_check_heap(ctx, len + 1);
@@ -1912,8 +1885,8 @@
 
 uw_Basis_string uw_Basis_unurlifyString_fromClient(uw_context ctx, char **s) {
   char *new_s = uw_unurlify_advance(*s);
-  char *r, *s1, *s2;
-  int len, n;
+  char *r;
+  int len;
 
   len = strlen(*s);
   uw_check_heap(ctx, len + 1);
@@ -2765,7 +2738,7 @@
   int len = strlen(c);
   char *p = ctx->outHeaders.start;
 
-  while (p = strstr(p, "\nSet-Cookie: ")) {
+  while ((p = strstr(p, "\nSet-Cookie: "))) {
     char *p2;
     p += 13;
     p2 = strchr(p, '=');
@@ -2786,12 +2759,12 @@
     }
   }
 
-  if (p = uw_Basis_requestHeader(ctx, "Cookie")) {
+  if ((p = uw_Basis_requestHeader(ctx, "Cookie"))) {
     char *p2;
 
     while (1) {
       if (!strncmp(p, c, len) && p[len] == '=') {
-        if (p2 = strchr(p, ';')) {
+        if ((p2 = strchr(p, ';'))) {
           size_t n = p2 - (p + len);
           char *r = uw_malloc(ctx, n);
           memcpy(r, p + 1 + len, n-1);
@@ -2799,7 +2772,7 @@
           return r;
         } else
           return p + 1 + len;
-      } else if (p = strchr(p, ';'))
+      } else if ((p = strchr(p, ';')))
         p += 2;
       else
         return NULL;
@@ -3194,7 +3167,7 @@
   uw_write_header(ctx, mimeType);
   uw_write_header(ctx, "\r\nContent-Length: ");
   ctx_buf_check(ctx, "headers", &ctx->outHeaders, INTS_MAX);
-  sprintf(ctx->outHeaders.front, "%d%n", b.size, &len);
+  sprintf(ctx->outHeaders.front, "%lu%n", (unsigned long)b.size, &len);
   ctx->outHeaders.front += len;
   uw_write_header(ctx, "\r\n");
 
@@ -3210,7 +3183,6 @@
 
 __attribute__((noreturn)) void uw_redirect(uw_context ctx, uw_Basis_string url) {
   cleanup *cl;
-  int len;
   char *s;
 
   ctx->returning_indirectly = 1;
@@ -3225,7 +3197,7 @@
   s = strchr(ctx->page.start, '\n');
   if (s) {
     char *s2;
-    for (++s; s2 = strchr(s, '\n'); s = s2+1) {
+    for (++s; (s2 = strchr(s, '\n')); s = s2+1) {
       *s2 = 0;
       if (!strncmp(s, "Set-Cookie: ", 12)) {
         uw_write_header(ctx, s);