]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Remove unnecessary apr_table_do() function casts
authorJacob Champion <jchampion@apache.org>
Thu, 10 Nov 2016 20:53:21 +0000 (20:53 +0000)
committerJacob Champion <jchampion@apache.org>
Thu, 10 Nov 2016 20:53:21 +0000 (20:53 +0000)
Function casts can cause hard-to-debug corruption issues if a
declaration is accidentally changed to be incompatible. Luckily, most of
the function casts for apr_table_do() calls are unnecessary. Remove
them, and adjust the signatures for helpers that weren't taking void* as
the first argument.

The remaining helper that requires a cast is http_filter.c's
form_header_field(), which is probably where many of these casts were
copy-pasted from. I have left it as-is: it has other direct callers
besides apr_table_do(), and it's already documented with warnings not to
change the function signature.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1769192 13f79535-47bb-0310-9956-ffa450edef68

modules/http/http_filters.c
modules/http2/h2_from_h1.c
modules/metadata/mod_headers.c
modules/session/mod_session.c
server/util_cookies.c

index b0ed5b009b55d5c911fbb51eb8e47fbd276a1d88..a583f3c1be9aa297118d87bbaec0c06c225071d4 100644 (file)
@@ -826,8 +826,7 @@ static void fixup_vary(request_rec *r)
      * its comma-separated fieldname values, and then add them to varies
      * if not already present in the array.
      */
-    apr_table_do((int (*)(void *, const char *, const char *))uniq_field_values,
-                 (void *) varies, r->headers_out, "Vary", NULL);
+    apr_table_do(uniq_field_values, varies, r->headers_out, "Vary", NULL);
 
     /* If we found any, replace old Vary fields with unique-ified value */
 
index cdb444650b718ef8444b5829778a5eeba4b3f45a..f1ea12de2fb7b7a731588cd9f7ba472dabe4bf28 100644 (file)
@@ -103,8 +103,7 @@ static void fix_vary(request_rec *r)
      * its comma-separated fieldname values, and then add them to varies
      * if not already present in the array.
      */
-    apr_table_do((int (*)(void *, const char *, const char *))uniq_field_values,
-                 (void *) varies, r->headers_out, "Vary", NULL);
+    apr_table_do(uniq_field_values, varies, r->headers_out, "Vary", NULL);
     
     /* If we found any, replace old Vary fields with unique-ified value */
     
@@ -275,8 +274,7 @@ static h2_headers *create_response(h2_task *task, request_rec *r)
     
     set_basic_http_header(headers, r, r->pool);
     if (r->status == HTTP_NOT_MODIFIED) {
-        apr_table_do((int (*)(void *, const char *, const char *)) copy_header,
-                     (void *) headers, r->headers_out,
+        apr_table_do(copy_header, headers, r->headers_out,
                      "ETag",
                      "Content-Location",
                      "Expires",
@@ -290,8 +288,7 @@ static h2_headers *create_response(h2_task *task, request_rec *r)
                      NULL);
     }
     else {
-        apr_table_do((int (*)(void *, const char *, const char *)) copy_header,
-                     (void *) headers, r->headers_out, NULL);
+        apr_table_do(copy_header, headers, r->headers_out, NULL);
     }
     
     return h2_headers_rcreate(r, r->status, headers, r->pool);
index 3fd98042277a398f3bcc29b5e5690c1a0b5e422b..4b4c606886c985f5a1f25c804908b3867a4d4cf3 100644 (file)
@@ -666,13 +666,15 @@ static const char *process_regexp(header_entry *hdr, const char *value,
     return ret;
 }
 
-static int echo_header(echo_do *v, const char *key, const char *val)
+static int echo_header(void *v, const char *key, const char *val)
 {
+    edit_do *ed = v;
+
     /* If the input header (key) matches the regex, echo it intact to
      * r->headers_out.
      */
-    if (!ap_regexec(v->hdr->regex, key, 0, NULL, 0)) {
-        apr_table_add(v->r->headers_out, key, val);
+    if (!ap_regexec(ed->hdr->regex, key, 0, NULL, 0)) {
+        apr_table_add(ed->r->headers_out, key, val);
     }
 
     return 1;
@@ -808,8 +810,7 @@ static int do_headers_fixup(request_rec *r, apr_table_t *headers,
         case hdr_echo:
             v.r = r;
             v.hdr = hdr;
-            apr_table_do((int (*) (void *, const char *, const char *))
-                         echo_header, (void *) &v, r->headers_in, NULL);
+            apr_table_do(echo_header, &v, r->headers_in, NULL);
             break;
         case hdr_edit:
         case hdr_edit_r:
index 9761e50669767b1dfae8536db1f18964baa84c85..c573f981a74fe9c7cb0b9bb4b5f988c4ee29f5e0 100644 (file)
@@ -311,15 +311,16 @@ static apr_status_t ap_session_set(request_rec * r, session_rec * z,
     return APR_SUCCESS;
 }
 
-static int identity_count(int *count, const char *key, const char *val)
+static int identity_count(void *v, const char *key, const char *val)
 {
+    int *count = v;
     *count += strlen(key) * 3 + strlen(val) * 3 + 1;
     return 1;
 }
 
-static int identity_concat(char *buffer, const char *key, const char *val)
+static int identity_concat(void *v, const char *key, const char *val)
 {
-    char *slider = buffer;
+    char *slider = v;
     int length = strlen(slider);
     slider += length;
     if (length) {
@@ -356,11 +357,9 @@ static apr_status_t session_identity_encode(request_rec * r, session_rec * z)
         char *expiry = apr_psprintf(z->pool, "%" APR_INT64_T_FMT, z->expiry);
         apr_table_setn(z->entries, SESSION_EXPIRY, expiry);
     }
-    apr_table_do((int (*) (void *, const char *, const char *))
-                 identity_count, &length, z->entries, NULL);
+    apr_table_do(identity_count, &length, z->entries, NULL);
     buffer = apr_pcalloc(r->pool, length + 1);
-    apr_table_do((int (*) (void *, const char *, const char *))
-                 identity_concat, buffer, z->entries, NULL);
+    apr_table_do(identity_concat, buffer, z->entries, NULL);
     z->encoded = buffer;
     return OK;
 
index 5139aecd4c48ec210025d8324647492fd78a80d0..82a514fcc66f13b7020c5df4d9442f5d6c6bd6d6 100644 (file)
@@ -174,8 +174,9 @@ AP_DECLARE(apr_status_t) ap_cookie_remove2(request_rec * r, const char *name2, c
  * $path or other attributes following our cookie if present. If we end
  * up with an empty cookie, remove the whole header.
  */
-static int extract_cookie_line(ap_cookie_do * v, const char *key, const char *val)
+static int extract_cookie_line(void *varg, const char *key, const char *val)
 {
+    ap_cookie_do *v = varg;
     char *last1, *last2;
     char *cookie = apr_pstrdup(v->r->pool, val);
     const char *name = apr_pstrcat(v->r->pool, v->name ? v->name : "", "=", NULL);
@@ -252,8 +253,7 @@ AP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const
     v.duplicated = 0;
     v.name = name;
 
-    apr_table_do((int (*) (void *, const char *, const char *))
-                 extract_cookie_line, (void *) &v, r->headers_in,
+    apr_table_do(extract_cookie_line, &v, r->headers_in,
                  "Cookie", "Cookie2", NULL);
     if (v.duplicated) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00011) LOG_PREFIX