CLEANUP: Use the ist() macro whenever possible
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`.
diff --git a/src/check.c b/src/check.c
index 0fab0d4..ba9c1f3 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1851,7 +1851,7 @@
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;
diff --git a/src/fcgi-app.c b/src/fcgi-app.c
index f4ce40c..71f6dd4 100644
--- a/src/fcgi-app.c
+++ b/src/fcgi-app.c
@@ -854,7 +854,7 @@
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 @@
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;
diff --git a/src/http_ana.c b/src/http_ana.c
index 5536c04..c124544 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -2733,7 +2733,7 @@
/* 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))
diff --git a/src/listener.c b/src/listener.c
index 48ba8e0..400a7eb 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -1496,7 +1496,7 @@
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]);
diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c
index 70b3d22..fabc83e 100644
--- a/src/mux_fcgi.c
+++ b/src/mux_fcgi.c
@@ -1269,7 +1269,7 @@
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 @@
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;
}
}
diff --git a/src/mux_h1.c b/src/mux_h1.c
index 17ce315..215153c 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -3585,7 +3585,7 @@
}
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);
diff --git a/src/server.c b/src/server.c
index b6a1bc2..d570e67 100644
--- a/src/server.c
+++ b/src/server.c
@@ -551,7 +551,7 @@
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]);
diff --git a/src/stats.c b/src/stats.c
index 2c595fb..67d85a7 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -4057,7 +4057,7 @@
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;
}
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index ef9df24..0fe3d10 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -2273,7 +2273,7 @@
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 @@
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 @@
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 @@
}
}
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 @@
}
}
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 @@
}
}
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 @@
}
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 @@
}
}
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 @@
}
}
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 @@
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 @@
}
}
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 @@
/* 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;