summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2022-11-02 21:45:40 +0100
committerAlejandro Colomar <alx@nginx.com>2022-11-04 00:30:27 +0100
commit1b05161107112f09c15b128090284bb6de5b4f70 (patch)
tree28156b8acfa701426075856ba3355d7311e7fdab /src
parenta03274456b54cbc39e220b9dd73c3fc3fb935e46 (diff)
downloadunit-1b05161107112f09c15b128090284bb6de5b4f70.tar.gz
unit-1b05161107112f09c15b128090284bb6de5b4f70.tar.bz2
Removed the unsafe nxt_memcmp() wrapper for memcmp(3).
The casts are unnecessary, since memcmp(3)'s arguments are 'void *'. It might have been necessary in the times of K&R, where 'void *' didn't exist. Nowadays, it's unnecessary, and _very_ unsafe, since casts can hide all classes of bugs by silencing most compiler warnings. The changes from nxt_memcmp() to memcmp(3) were scripted: $ find src/ -type f \ | grep '\.[ch]$' \ | xargs sed -i 's/nxt_memcmp/memcmp/' Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'src')
-rw-r--r--src/nxt_application.c2
-rw-r--r--src/nxt_conf.c6
-rw-r--r--src/nxt_controller.c4
-rw-r--r--src/nxt_errno.c6
-rw-r--r--src/nxt_h1proto.c6
-rw-r--r--src/nxt_http_parse.c6
-rw-r--r--src/nxt_http_route.c18
-rw-r--r--src/nxt_http_route_addr.c4
-rw-r--r--src/nxt_http_variables.c4
-rw-r--r--src/nxt_openssl.c2
-rw-r--r--src/nxt_php_sapi.c2
-rw-r--r--src/nxt_sockaddr.c6
-rw-r--r--src/nxt_string.c4
-rw-r--r--src/nxt_string.h10
-rw-r--r--src/test/nxt_http_parse_test.c2
-rw-r--r--src/test/nxt_tests.c2
-rw-r--r--src/test/nxt_utf8_file_name_test.c2
-rw-r--r--src/test/nxt_utf8_test.c2
18 files changed, 42 insertions, 46 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 556f1ffb..786c768b 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -366,7 +366,7 @@ nxt_discovery_module(nxt_task_t *task, nxt_mp_t *mp, nxt_array_t *modules,
&app->type, app->version, name);
if (app->compat_length != sizeof(compat)
- || nxt_memcmp(app->compat, compat, sizeof(compat)) != 0)
+ || memcmp(app->compat, compat, sizeof(compat)) != 0)
{
nxt_log(task, NXT_LOG_NOTICE, "incompatible module %s", name);
diff --git a/src/nxt_conf.c b/src/nxt_conf.c
index c6312f3d..d04aa45c 100644
--- a/src/nxt_conf.c
+++ b/src/nxt_conf.c
@@ -1389,7 +1389,7 @@ nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
case 't':
if (nxt_fast_path(end - start >= 4
- && nxt_memcmp(start, "true", 4) == 0))
+ && memcmp(start, "true", 4) == 0))
{
value->u.boolean = 1;
value->type = NXT_CONF_VALUE_BOOLEAN;
@@ -1401,7 +1401,7 @@ nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
case 'f':
if (nxt_fast_path(end - start >= 5
- && nxt_memcmp(start, "false", 5) == 0))
+ && memcmp(start, "false", 5) == 0))
{
value->u.boolean = 0;
value->type = NXT_CONF_VALUE_BOOLEAN;
@@ -1413,7 +1413,7 @@ nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
case 'n':
if (nxt_fast_path(end - start >= 4
- && nxt_memcmp(start, "null", 4) == 0))
+ && memcmp(start, "null", 4) == 0))
{
value->type = NXT_CONF_VALUE_NULL;
return start + 4;
diff --git a/src/nxt_controller.c b/src/nxt_controller.c
index 99c7ca10..5f3e55ef 100644
--- a/src/nxt_controller.c
+++ b/src/nxt_controller.c
@@ -1263,7 +1263,7 @@ nxt_controller_process_config(nxt_task_t *task, nxt_controller_request_t *req,
/* Skip UTF-8 BOM. */
if (nxt_buf_mem_used_size(mbuf) >= 3
- && nxt_memcmp(mbuf->pos, "\xEF\xBB\xBF", 3) == 0)
+ && memcmp(mbuf->pos, "\xEF\xBB\xBF", 3) == 0)
{
mbuf->pos += 3;
}
@@ -1940,7 +1940,7 @@ nxt_controller_process_control(nxt_task_t *task,
}
if (!nxt_str_start(path, "applications/", 13)
- || nxt_memcmp(path->start + path->length - 8, "/restart", 8) != 0)
+ || memcmp(path->start + path->length - 8, "/restart", 8) != 0)
{
goto not_found;
}
diff --git a/src/nxt_errno.c b/src/nxt_errno.c
index 869a970f..47479a82 100644
--- a/src/nxt_errno.c
+++ b/src/nxt_errno.c
@@ -78,7 +78,7 @@ nxt_strerror_start(void)
if (length == 0 /* HP-UX empty strings. */
|| nxt_errno == NXT_EINVAL
- || nxt_memcmp(msg, "Unknown error", 13) == 0)
+ || memcmp(msg, "Unknown error", 13) == 0)
{
invalid++;
continue;
@@ -86,8 +86,8 @@ nxt_strerror_start(void)
#if (NXT_AIX)
- if (nxt_memcmp(msg, "Error ", 6) == 0
- && nxt_memcmp(msg + length - 10, " occurred.", 9) == 0)
+ if (memcmp(msg, "Error ", 6) == 0
+ && memcmp(msg + length - 10, " occurred.", 9) == 0)
{
invalid++;
continue;
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c
index 852b4866..3acba088 100644
--- a/src/nxt_h1proto.c
+++ b/src/nxt_h1proto.c
@@ -823,7 +823,7 @@ nxt_h1p_transfer_encoding(void *ctx, nxt_http_field_t *field, uintptr_t data)
field->hopbyhop = 1;
if (field->value_length == 7
- && nxt_memcmp(field->value, "chunked", 7) == 0)
+ && memcmp(field->value, "chunked", 7) == 0)
{
te = NXT_HTTP_TE_CHUNKED;
@@ -2594,7 +2594,7 @@ nxt_h1p_peer_header_parse(nxt_http_peer_t *peer, nxt_buf_mem_t *bm)
p = bm->pos;
- if (nxt_slow_path(nxt_memcmp(p, "HTTP/1.", 7) != 0
+ if (nxt_slow_path(memcmp(p, "HTTP/1.", 7) != 0
|| (p[7] != '0' && p[7] != '1')))
{
return NXT_ERROR;
@@ -2868,7 +2868,7 @@ nxt_h1p_peer_transfer_encoding(void *ctx, nxt_http_field_t *field,
field->skip = 1;
if (field->value_length == 7
- && nxt_memcmp(field->value, "chunked", 7) == 0)
+ && memcmp(field->value, "chunked", 7) == 0)
{
r->peer->proto.h1->chunked = 1;
}
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 1bb4291f..f39d8f67 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -357,7 +357,7 @@ space_after_target:
} while (*p == ' ');
- if (nxt_memcmp(p, "HTTP/", nxt_min(end - p, 5)) == 0) {
+ if (memcmp(p, "HTTP/", nxt_min(end - p, 5)) == 0) {
switch (end - p) {
case 8:
@@ -412,7 +412,7 @@ space_after_target:
if (nxt_fast_path(ver.ui64 == http11.ui64
|| ver.ui64 == http10.ui64
- || (nxt_memcmp(ver.str, "HTTP/1.", 7) == 0
+ || (memcmp(ver.str, "HTTP/1.", 7) == 0
&& ver.s.minor >= '0' && ver.s.minor <= '9')))
{
rp->version.ui64 = ver.ui64;
@@ -464,7 +464,7 @@ space_after_target:
return nxt_http_parse_field_name(rp, pos, end);
}
- if (nxt_memcmp(ver.s.prefix, "HTTP/", 5) == 0
+ if (memcmp(ver.s.prefix, "HTTP/", 5) == 0
&& ver.s.major >= '0' && ver.s.major <= '9'
&& ver.s.point == '.'
&& ver.s.minor >= '0' && ver.s.minor <= '9')
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index cdc9077f..9aa23899 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -1740,15 +1740,15 @@ nxt_http_route_addr_pattern_match(nxt_http_route_addr_pattern_t *p,
break;
case NXT_HTTP_ROUTE_ADDR_EXACT:
- match = (nxt_memcmp(&sin->sin_addr, &p->addr.v4.start,
+ match = (memcmp(&sin->sin_addr, &p->addr.v4.start,
sizeof(struct in_addr))
== 0);
break;
case NXT_HTTP_ROUTE_ADDR_RANGE:
- match = (nxt_memcmp(&sin->sin_addr, &p->addr.v4.start,
+ match = (memcmp(&sin->sin_addr, &p->addr.v4.start,
sizeof(struct in_addr)) >= 0
- && nxt_memcmp(&sin->sin_addr, &p->addr.v4.end,
+ && memcmp(&sin->sin_addr, &p->addr.v4.end,
sizeof(struct in_addr)) <= 0);
break;
@@ -1786,15 +1786,15 @@ nxt_http_route_addr_pattern_match(nxt_http_route_addr_pattern_t *p,
break;
case NXT_HTTP_ROUTE_ADDR_EXACT:
- match = (nxt_memcmp(&sin6->sin6_addr, &p->addr.v6.start,
+ match = (memcmp(&sin6->sin6_addr, &p->addr.v6.start,
sizeof(struct in6_addr))
== 0);
break;
case NXT_HTTP_ROUTE_ADDR_RANGE:
- match = (nxt_memcmp(&sin6->sin6_addr, &p->addr.v6.start,
+ match = (memcmp(&sin6->sin6_addr, &p->addr.v6.start,
sizeof(struct in6_addr)) >= 0
- && nxt_memcmp(&sin6->sin6_addr, &p->addr.v6.end,
+ && memcmp(&sin6->sin6_addr, &p->addr.v6.end,
sizeof(struct in6_addr)) <= 0);
break;
@@ -1937,7 +1937,7 @@ nxt_http_route_test_argument(nxt_http_request_t *r,
if (rule->u.name.hash == nv->hash
&& rule->u.name.length == nv->name_length
- && nxt_memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
+ && memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
{
ret = nxt_http_route_test_rule(r, rule, nv->value,
nv->value_length);
@@ -2015,7 +2015,7 @@ nxt_http_route_test_cookie(nxt_http_request_t *r,
if (rule->u.name.hash == nv->hash
&& rule->u.name.length == nv->name_length
- && nxt_memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
+ && memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
{
ret = nxt_http_route_test_rule(r, rule, nv->value,
nv->value_length);
@@ -2158,7 +2158,7 @@ nxt_http_route_memcmp(u_char *start, u_char *test, size_t test_length,
nxt_int_t n;
if (case_sensitive) {
- n = nxt_memcmp(start, test, test_length);
+ n = memcmp(start, test, test_length);
} else {
n = nxt_memcasecmp(start, test, test_length);
diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c
index 34455af4..06b30d29 100644
--- a/src/nxt_http_route_addr.c
+++ b/src/nxt_http_route_addr.c
@@ -115,7 +115,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp,
return NXT_ADDR_PATTERN_FORMAT_ERROR;
}
- if (nxt_slow_path(nxt_memcmp(&inet6->start, &inet6->end,
+ if (nxt_slow_path(memcmp(&inet6->start, &inet6->end,
sizeof(struct in6_addr)) > 0))
{
return NXT_ADDR_PATTERN_RANGE_OVERLAP_ERROR;
@@ -223,7 +223,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp,
return NXT_ADDR_PATTERN_FORMAT_ERROR;
}
- if (nxt_slow_path(nxt_memcmp(&inet->start, &inet->end,
+ if (nxt_slow_path(memcmp(&inet->start, &inet->end,
sizeof(struct in_addr)) > 0))
{
return NXT_ADDR_PATTERN_RANGE_OVERLAP_ERROR;
diff --git a/src/nxt_http_variables.c b/src/nxt_http_variables.c
index e01bcdb9..eb341716 100644
--- a/src/nxt_http_variables.c
+++ b/src/nxt_http_variables.c
@@ -421,7 +421,7 @@ nxt_http_var_arg(nxt_task_t *task, nxt_str_t *str, void *ctx, uint16_t field)
if (vf->hash == nv->hash
&& vf->name.length == nv->name_length
- && nxt_memcmp(vf->name.start, nv->name, nv->name_length) == 0)
+ && memcmp(vf->name.start, nv->name, nv->name_length) == 0)
{
str->start = nv->value;
str->length = nv->value_length;
@@ -499,7 +499,7 @@ nxt_http_var_cookie(nxt_task_t *task, nxt_str_t *str, void *ctx, uint16_t field)
if (vf->hash == nv->hash
&& vf->name.length == nv->name_length
- && nxt_memcmp(vf->name.start, nv->name, nv->name_length) == 0)
+ && memcmp(vf->name.start, nv->name, nv->name_length) == 0)
{
str->start = nv->value;
str->length = nv->value_length;
diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c
index 55611511..f56135f3 100644
--- a/src/nxt_openssl.c
+++ b/src/nxt_openssl.c
@@ -780,7 +780,7 @@ nxt_tls_ticket_key_callback(SSL *s, unsigned char *name, unsigned char *iv,
/* decrypt session ticket */
do {
- if (nxt_memcmp(name, ticket[i].name, 16) == 0) {
+ if (memcmp(name, ticket[i].name, 16) == 0) {
goto found;
}
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c
index 924dd4e6..126a4684 100644
--- a/src/nxt_php_sapi.c
+++ b/src/nxt_php_sapi.c
@@ -1036,7 +1036,7 @@ nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r)
script_name = *ctx->index;
} else if (path.length < 4
- || nxt_memcmp(path.start + (path.length - 4), ".php", 4) != 0)
+ || memcmp(path.start + (path.length - 4), ".php", 4) != 0)
{
char tpath[PATH_MAX];
nxt_int_t ec;
diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c
index 86c3335e..a076f286 100644
--- a/src/nxt_sockaddr.c
+++ b/src/nxt_sockaddr.c
@@ -382,7 +382,7 @@ nxt_sockaddr_cmp(nxt_sockaddr_t *sa1, nxt_sockaddr_t *sa2)
return 0;
}
- if (nxt_memcmp(&sa1->u.sockaddr_in6.sin6_addr,
+ if (memcmp(&sa1->u.sockaddr_in6.sin6_addr,
&sa2->u.sockaddr_in6.sin6_addr, 16)
!= 0)
{
@@ -401,7 +401,7 @@ nxt_sockaddr_cmp(nxt_sockaddr_t *sa1, nxt_sockaddr_t *sa2)
length = sa1->socklen - offsetof(struct sockaddr_un, sun_path);
- if (nxt_memcmp(&sa1->u.sockaddr_un.sun_path,
+ if (memcmp(&sa1->u.sockaddr_un.sun_path,
&sa2->u.sockaddr_un.sun_path, length)
!= 0)
{
@@ -550,7 +550,7 @@ nxt_sockaddr_parse_optport(nxt_mp_t *mp, nxt_str_t *addr)
return NULL;
}
- if (addr->length > 6 && nxt_memcmp(addr->start, "unix:", 5) == 0) {
+ if (addr->length > 6 && memcmp(addr->start, "unix:", 5) == 0) {
sa = nxt_sockaddr_unix_parse(mp, addr);
} else if (addr->start[0] == '[' || nxt_inet6_probe(addr)) {
diff --git a/src/nxt_string.c b/src/nxt_string.c
index 4d89c23c..1ca595a1 100644
--- a/src/nxt_string.c
+++ b/src/nxt_string.c
@@ -257,7 +257,7 @@ nxt_memstrn(const u_char *s, const u_char *end, const char *ss, size_t length)
return NULL;
}
- if (nxt_memcmp(s, s2, length) == 0) {
+ if (memcmp(s, s2, length) == 0) {
return (u_char *) s - 1;
}
}
@@ -325,7 +325,7 @@ nxt_rmemstrn(const u_char *s, const u_char *end, const char *ss, size_t length)
c1 = *s1;
if (c1 == c2) {
- if (nxt_memcmp(s1 + 1, s2, length) == 0) {
+ if (memcmp(s1 + 1, s2, length) == 0) {
return (u_char *) s1;
}
}
diff --git a/src/nxt_string.h b/src/nxt_string.h
index a8673c61..d021df69 100644
--- a/src/nxt_string.h
+++ b/src/nxt_string.h
@@ -66,10 +66,6 @@ nxt_cpymem(void *dst, const void *src, size_t length)
(void) memmove(dst, src, length)
-#define nxt_memcmp(s1, s2, length) \
- memcmp((char *) s1, (char *) s2, length)
-
-
#define nxt_memchr(s, c, length) \
memchr((char *) s, c, length)
@@ -132,7 +128,7 @@ NXT_EXPORT char *nxt_str_cstrz(nxt_mp_t *mp, const nxt_str_t *src);
#define nxt_strstr_eq(s1, s2) \
(((s1)->length == (s2)->length) \
- && (nxt_memcmp((s1)->start, (s2)->start, (s1)->length) == 0))
+ && (memcmp((s1)->start, (s2)->start, (s1)->length) == 0))
#define nxt_strcasestr_eq(s1, s2) \
@@ -141,11 +137,11 @@ NXT_EXPORT char *nxt_str_cstrz(nxt_mp_t *mp, const nxt_str_t *src);
#define nxt_str_eq(s, p, _length) \
- (((s)->length == _length) && (nxt_memcmp((s)->start, p, _length) == 0))
+ (((s)->length == _length) && (memcmp((s)->start, p, _length) == 0))
#define nxt_str_start(s, p, _length) \
- (((s)->length >= _length) && (nxt_memcmp((s)->start, p, _length) == 0))
+ (((s)->length >= _length) && (memcmp((s)->start, p, _length) == 0))
#define nxt_strchr_eq(s, c) \
diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c
index 540309c1..5f1a518c 100644
--- a/src/test/nxt_http_parse_test.c
+++ b/src/test/nxt_http_parse_test.c
@@ -753,7 +753,7 @@ nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
return NXT_ERROR;
}
- if (nxt_memcmp(rp->version.str, test->version, 8) != 0) {
+ if (memcmp(rp->version.str, test->version, 8) != 0) {
nxt_log_alert(log, "http parse test case failed:\n"
" - request:\n\"%V\"\n"
" - version: \"%*s\" (expected: \"%*s\")", request,
diff --git a/src/test/nxt_tests.c b/src/test/nxt_tests.c
index f5a1cbd4..03a2a1df 100644
--- a/src/test/nxt_tests.c
+++ b/src/test/nxt_tests.c
@@ -41,7 +41,7 @@ main(int argc, char **argv)
#if (NXT_TEST_RTDTSC)
if (nxt_process_argv[1] != NULL
- && nxt_memcmp(nxt_process_argv[1], "rbm", 3) == 0)
+ && memcmp(nxt_process_argv[1], "rbm", 3) == 0)
{
if (nxt_rbtree1_mb_start(thr) != NXT_OK) {
return 1;
diff --git a/src/test/nxt_utf8_file_name_test.c b/src/test/nxt_utf8_file_name_test.c
index 30546ffb..5723e19b 100644
--- a/src/test/nxt_utf8_file_name_test.c
+++ b/src/test/nxt_utf8_file_name_test.c
@@ -129,7 +129,7 @@ nxt_utf8_file_name_test(nxt_thread_t *thr)
nxt_file_close(&task, &lc_file);
- if (n != 4 || nxt_memcmp(utf8, test, 4) != 0) {
+ if (n != 4 || memcmp(utf8, test, 4) != 0) {
nxt_log_alert(thr->log, "nxt_file_read() mismatch");
nxt_file_delete(lc_file.name);
diff --git a/src/test/nxt_utf8_test.c b/src/test/nxt_utf8_test.c
index bca9a737..31e5bff9 100644
--- a/src/test/nxt_utf8_test.c
+++ b/src/test/nxt_utf8_test.c
@@ -59,7 +59,7 @@ nxt_utf8_overlong(nxt_thread_t *thr, u_char *overlong, size_t len)
size = (p != NULL) ? p - utf8 : 0;
- if (len != size || nxt_memcmp(overlong, utf8, size) != 0) {
+ if (len != size || memcmp(overlong, utf8, size) != 0) {
u = 0;
for (i = 0; i < len; i++) {