1. redundant null tests

2. http decode can be linear instead of (n^2) with two pointers.

Index: cgi.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/cgi.c,v
retrieving revision 1.1
diff -u -p -r1.1 cgi.c
--- cgi.c       11 Jul 2014 15:37:22 -0000      1.1
+++ cgi.c       11 Jul 2014 15:50:48 -0000
@@ -161,7 +161,7 @@ html_printquery(const struct req *req)
        }
        if (NULL != req->q.expr) {
                printf("&expr=");
-               html_print(req->q.expr ? req->q.expr : "");
+               html_print(req->q.expr);
        }
 }
 
@@ -280,11 +280,13 @@ static int
 http_decode(char *p)
 {
        char             hex[3];
+       char            *q;
        int              c;
 
        hex[2] = '\0';
 
-       for ( ; '\0' != *p; p++) {
+       q = p;
+       for ( ; '\0' != *p; p++, q++) {
                if ('%' == *p) {
                        if ('\0' == (hex[0] = *(p + 1)))
                                return(0);
@@ -295,13 +297,13 @@ http_decode(char *p)
                        if ('\0' == c)
                                return(0);
 
-                       *p = (char)c;
-                       memmove(p + 1, p + 3, strlen(p + 3) + 1);
+                       *q = (char)c;
+                       p += 2;
                } else
-                       *p = '+' == *p ? ' ' : *p;
+                       *q = '+' == *p ? ' ' : *p;
        }
 
-       *p = '\0';
+       *q = '\0';
        return(1);
 }
 

Reply via email to