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>
This commit is contained in:
Alejandro Colomar
2022-11-02 21:45:40 +01:00
parent a03274456b
commit 1b05161107
18 changed files with 42 additions and 46 deletions

View File

@@ -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;
}