]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: Use the ist() macro whenever possible
authorTim Duesterhus <tim@bastelstu.be>
Thu, 4 Mar 2021 16:31:47 +0000 (17:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 07:28:53 +0000 (08:28 +0100)
Refactoring performed with the following Coccinelle patch:

    @@
    char *s;
    @@

    (
    - ist2(s, strlen(s))
    + ist(s)
    |
    - ist2(strdup(s), strlen(s))
    + ist(strdup(s))
    )

Note that this replacement is safe even in the strdup() case, because `ist()`
will not call `strlen()` on a `NULL` pointer. Instead is inserts a length of
`0`, effectively resulting in `IST_NULL`.

src/check.c
src/fcgi-app.c
src/http_ana.c
src/listener.c
src/mux_fcgi.c
src/mux_h1.c
src/server.c
src/stats.c
src/tcpcheck.c

index 0fab0d4128c5d06f97ec89a31b16fde880ee257b..ba9c1f315cada5338c5887323de951b30064f028 100644 (file)
@@ -1851,7 +1851,7 @@ static int srv_parse_check_proto(char **args, int *cur_arg,
                memprintf(err, "'%s' : missing value", args[*cur_arg]);
                goto error;
        }
-       newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1])));
+       newsrv->check.mux_proto = get_mux_proto(ist(args[*cur_arg + 1]));
        if (!newsrv->check.mux_proto) {
                memprintf(err, "'%s' :  unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
                goto error;
index f4ce40c2150c829940899ce3ecff9ea876f868c3..71f6dd48b5b66bfd12baf91a815d4e1e9a8d5deb 100644 (file)
@@ -854,7 +854,7 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
                if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
                        goto out;
                istfree(&curapp->docroot);
-               curapp->docroot = ist2(strdup(args[1]), strlen(args[1]));
+               curapp->docroot = ist(strdup(args[1]));
                if (!isttest(curapp->docroot)) {
                        ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        err_code |= ERR_ALERT | ERR_ABORT;
@@ -887,7 +887,7 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
                if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
                        goto out;
                istfree(&curapp->index);
-               curapp->index = ist2(strdup(args[1]), strlen(args[1]));
+               curapp->index = ist(strdup(args[1]));
                if (!isttest(curapp->index)) {
                        ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        err_code |= ERR_ALERT | ERR_ABORT;
index 5536c0402f9a3515afd1f42c115ce4f422aa38a1..c1245442f14d5ee9b6ca5f0cafd06591af1e9f1d 100644 (file)
@@ -2733,7 +2733,7 @@ int http_res_set_status(unsigned int status, struct ist reason, struct stream *s
        /* Do we have a custom reason format string? */
        if (!isttest(reason)) {
                const char *str = http_get_reason(status);
-               reason = ist2(str, strlen(str));
+               reason = ist(str);
        }
 
        if (!http_replace_res_status(htx, ist2(trash.area, trash.data), reason))
index 48ba8e0e4db7ea132eaa012afe89256326a2bd61..400a7ebc2cc9d38dbb8bd9011325f5d27a0d2109 100644 (file)
@@ -1496,7 +1496,7 @@ static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct b
                return ERR_ALERT | ERR_FATAL;
        }
 
-       proto = ist2(args[cur_arg + 1], strlen(args[cur_arg + 1]));
+       proto = ist(args[cur_arg + 1]);
        conf->mux_proto = get_mux_proto(proto);
        if (!conf->mux_proto) {
                memprintf(err, "'%s' :  unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]);
index 70b3d227275c4fc367afee093e239f2be079137c..fabc83e90691e496edd0f6dc1d60aac436969640 100644 (file)
@@ -1269,7 +1269,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
                                if (addr_to_str(cli_conn->dst, b_tail(params->p), b_room(params->p)) != -1)
                                        ptr = b_tail(params->p);
                        if (ptr) {
-                               params->srv_name = ist2(ptr, strlen(ptr));
+                               params->srv_name = ist(ptr);
                                params->p->data += params->srv_name.len;
                        }
                }
@@ -1281,7 +1281,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
                        if (addr_to_str(cli_conn->src, b_tail(params->p), b_room(params->p)) != -1)
                                ptr = b_tail(params->p);
                if (ptr) {
-                       params->rem_addr = ist2(ptr, strlen(ptr));
+                       params->rem_addr = ist(ptr);
                        params->p->data += params->rem_addr.len;
                }
        }
index 17ce3152fb7285ca391ba9b71db6f61415d2fe22..215153c096251e353e134a4f33a0703f56e32a69 100644 (file)
@@ -3585,7 +3585,7 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err)
        }
 
        entry->node.key = strdup(from);
-       entry->name = ist2(strdup(to), strlen(to));
+       entry->name = ist(strdup(to));
        if (!entry->node.key || !isttest(entry->name)) {
                free(entry->node.key);
                istfree(&entry->name);
index b6a1bc29c8adc3a0eebc8ae80398110d9daed747..d570e67a2bf73a1fd619b74202b4a7e66508f195 100644 (file)
@@ -551,7 +551,7 @@ static int srv_parse_proto(char **args, int *cur_arg,
                memprintf(err, "'%s' : missing value", args[*cur_arg]);
                return ERR_ALERT | ERR_FATAL;
        }
-       proto = ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1]));
+       proto = ist(args[*cur_arg + 1]);
        newsrv->mux_proto = get_mux_proto(proto);
        if (!newsrv->mux_proto) {
                memprintf(err, "'%s' :  unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
index 2c595fbaa90be98c32b35f12baea4e6ceabdb5dc..67d85a7f0568a96fee9ab222f660c124df192cc8 100644 (file)
@@ -4057,7 +4057,7 @@ static int stats_send_http_headers(struct stream_interface *si, struct htx *htx)
 
        if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
                const char *refresh = U2A(uri->refresh);
-               if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
+               if (!htx_add_header(htx, ist("Refresh"), ist(refresh)))
                        goto full;
        }
 
index ef9df24a8bf6e3df6238b2848e5f6a3a03092abb..0fe3d10cd34078268277e658df2315878da70189 100644 (file)
@@ -2273,7 +2273,7 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr
                                memprintf(errmsg, "'%s' expects a MUX protocol as argument.", args[cur_arg]);
                                goto error;
                        }
-                       mux_proto = get_mux_proto(ist2(args[cur_arg+1], strlen(args[cur_arg+1])));
+                       mux_proto = get_mux_proto(ist(args[cur_arg + 1]));
                        if (!mux_proto) {
                                memprintf(errmsg, "'%s' : unknown MUX protocol '%s'.", args[cur_arg], args[cur_arg+1]);
                                goto error;
@@ -2439,7 +2439,7 @@ struct tcpcheck_rule *parse_tcpcheck_send(char **args, int cur_arg, struct proxy
 
        switch (chk->send.type) {
        case TCPCHK_SEND_STRING:
-               chk->send.data = ist2(strdup(data), strlen(data));
+               chk->send.data = ist(strdup(data));
                if (!isttest(chk->send.data)) {
                        memprintf(errmsg, "out of memory");
                        goto error;
@@ -2535,8 +2535,8 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
                                 strcasecmp(args[cur_arg+1], "transfer-encoding") == 0)
                                goto skip_hdr;
 
-                       hdrs[i].n = ist2(args[cur_arg+1], strlen(args[cur_arg+1]));
-                       hdrs[i].v = ist2(args[cur_arg+2], strlen(args[cur_arg+2]));
+                       hdrs[i].n = ist(args[cur_arg + 1]);
+                       hdrs[i].v = ist(args[cur_arg + 2]);
                        i++;
                  skip_hdr:
                        cur_arg += 2;
@@ -2605,7 +2605,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
                        }
                }
                else {
-                       chk->send.http.uri = ist2(strdup(uri), strlen(uri));
+                       chk->send.http.uri = ist(strdup(uri));
                        if (!isttest(chk->send.http.uri)) {
                                memprintf(errmsg, "out of memory");
                                goto error;
@@ -2613,7 +2613,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
                }
        }
        if (vsn) {
-               chk->send.http.vsn = ist2(strdup(vsn), strlen(vsn));
+               chk->send.http.vsn = ist(strdup(vsn));
                if (!isttest(chk->send.http.vsn)) {
                        memprintf(errmsg, "out of memory");
                        goto error;
@@ -2649,7 +2649,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
                        }
                }
                else {
-                       chk->send.http.body = ist2(strdup(body), strlen(body));
+                       chk->send.http.body = ist(strdup(body));
                        if (!isttest(chk->send.http.body)) {
                                memprintf(errmsg, "out of memory");
                                goto error;
@@ -3174,7 +3174,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
        }
        case TCPCHK_EXPECT_STRING:
        case TCPCHK_EXPECT_HTTP_BODY:
-               chk->expect.data = ist2(strdup(pattern), strlen(pattern));
+               chk->expect.data = ist(strdup(pattern));
                if (!isttest(chk->expect.data)) {
                        memprintf(errmsg, "out of memory");
                        goto error;
@@ -3229,7 +3229,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
                        }
                }
                else {
-                       chk->expect.hdr.name = ist2(strdup(npat), strlen(npat));
+                       chk->expect.hdr.name = ist(strdup(npat));
                        if (!isttest(chk->expect.hdr.name)) {
                                memprintf(errmsg, "out of memory");
                                goto error;
@@ -3259,7 +3259,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro
                        }
                }
                else {
-                       chk->expect.hdr.value = ist2(strdup(vpat), strlen(vpat));
+                       chk->expect.hdr.value = ist(strdup(vpat));
                        if (!isttest(chk->expect.hdr.value)) {
                                memprintf(errmsg, "out of memory");
                                goto error;
@@ -3621,7 +3621,7 @@ int add_tcpcheck_expect_str(struct tcpcheck_rules *rules, const char *str)
        expect->ok_status = HCHK_STATUS_L7OKD;
        expect->err_status = HCHK_STATUS_L7RSP;
        expect->tout_status = HCHK_STATUS_L7TOUT;
-       expect->data = ist2(strdup(str), strlen(str));
+       expect->data = ist(strdup(str));
        if (!isttest(expect->data)) {
                pool_free(pool_head_tcpcheck_rule, tcpcheck);
                return 0;
@@ -4766,14 +4766,14 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s
                }
        }
        if (uri) {
-               chk->send.http.uri = ist2(strdup(uri), strlen(uri));
+               chk->send.http.uri = ist(strdup(uri));
                if (!isttest(chk->send.http.uri)) {
                        memprintf(errmsg, "out of memory");
                        goto error;
                }
        }
        if (vsn) {
-               chk->send.http.vsn = ist2(strdup(vsn), strlen(vsn));
+               chk->send.http.vsn = ist(strdup(vsn));
                if (!isttest(chk->send.http.vsn)) {
                        memprintf(errmsg, "out of memory");
                        goto error;
@@ -4820,7 +4820,7 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s
 
        /* Copy the body */
        if (body) {
-               chk->send.http.body = ist2(strdup(body), strlen(body));
+               chk->send.http.body = ist(strdup(body));
                if (!isttest(chk->send.http.body)) {
                        memprintf(errmsg, "out of memory");
                        goto error;