Re: [PATCH] CLEANUP: Use the ist() macro whenever possible

2021-03-04 Thread Willy Tarreau
Both cleanups applied, thank you Tim!
Willy



[PATCH] CLEANUP: Use the ist() macro whenever possible

2021-03-04 Thread Tim Duesterhus
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|  2 +-
 src/fcgi-app.c |  4 ++--
 src/http_ana.c |  2 +-
 src/listener.c |  2 +-
 src/mux_fcgi.c |  4 ++--
 src/mux_h1.c   |  2 +-
 src/server.c   |  2 +-
 src/stats.c|  2 +-
 src/tcpcheck.c | 28 ++--
 9 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/check.c b/src/check.c
index 0fab0d412..ba9c1f315 100644
--- a/src/check.c
+++ b/src/check.c
@@ -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;
diff --git a/src/fcgi-app.c b/src/fcgi-app.c
index f4ce40c21..71f6dd48b 100644
--- a/src/fcgi-app.c
+++ b/src/fcgi-app.c
@@ -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, 
_code))
goto out;
istfree(>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, 
_code))
goto out;
istfree(>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 5536c0402..c1245442f 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -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))
diff --git a/src/listener.c b/src/listener.c
index 48ba8e0e4..400a7ebc2 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -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]);
diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c
index 70b3d2272..fabc83e90 100644
--- a/src/mux_fcgi.c
+++ b/src/mux_fcgi.c
@@ -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;
}
}
diff --git a/src/mux_h1.c b/src/mux_h1.c
index