From 32c7acd46401530fdbd4e98508c9baaa705f8b53 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Fri, 3 Feb 2023 12:01:33 +0000 Subject: Replace rawmemchr (s, '\0') with strchr Almost all uses of rawmemchr find the end of a string. Since most targets use a generic implementation, replacing it with strchr is better since that is optimized by compilers into strlen (s) + s. Also fix the generic rawmemchr implementation to use a cast to unsigned char in the if statement. Reviewed-by: Adhemerval Zanella --- nscd/connections.c | 2 +- nscd/grpcache.c | 2 +- nscd/netgroupcache.c | 12 ++++++------ nscd/pwdcache.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'nscd') diff --git a/nscd/connections.c b/nscd/connections.c index b5fbb1a698..b1231a96db 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -1359,7 +1359,7 @@ cannot open /proc/self/cmdline: %m; disabling paranoia mode")); for (char *cp = cmdline; cp < cmdline + readlen;) { argv[argc++] = cp; - cp = (char *) rawmemchr (cp, '\0') + 1; + cp = strchr (cp, '\0') + 1; } argv[argc] = NULL; diff --git a/nscd/grpcache.c b/nscd/grpcache.c index eb20c4f1ab..cdd1071970 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -259,7 +259,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, /* Finally the stringified GID value. */ memcpy (cp, buf, n); char *key_copy = cp + key_offset; - assert (key_copy == (char *) rawmemchr (cp, '\0') + 1); + assert (key_copy == strchr (cp, '\0') + 1); assert (cp == dataset->strdata + total - offsetof (struct dataset, strdata)); diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c index 439dd4ba38..06b7d7b6ca 100644 --- a/nscd/netgroupcache.c +++ b/nscd/netgroupcache.c @@ -453,14 +453,14 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req, struct datahead *dh) { const char *group = key; - key = (char *) rawmemchr (key, '\0') + 1; + key = strchr (key, '\0') + 1; size_t group_len = key - group; const char *host = *key++ ? key : NULL; if (host != NULL) - key = (char *) rawmemchr (key, '\0') + 1; + key = strchr (key, '\0') + 1; const char *user = *key++ ? key : NULL; if (user != NULL) - key = (char *) rawmemchr (key, '\0') + 1; + key = strchr (key, '\0') + 1; const char *domain = *key++ ? key : NULL; if (__glibc_unlikely (debug_level > 0)) @@ -538,11 +538,11 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req, match anything is stored in the netgroup cache. */ if (host != NULL && *triplets != '\0') success = strcmp (host, triplets) == 0; - triplets = (const char *) rawmemchr (triplets, '\0') + 1; + triplets = strchr (triplets, '\0') + 1; if (success && user != NULL && *triplets != '\0') success = strcmp (user, triplets) == 0; - triplets = (const char *) rawmemchr (triplets, '\0') + 1; + triplets = strchr (triplets, '\0') + 1; if (success && (domain == NULL || *triplets == '\0' || strcmp (domain, triplets) == 0)) @@ -550,7 +550,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req, dataset->resp.result = 1; break; } - triplets = (const char *) rawmemchr (triplets, '\0') + 1; + triplets = strchr (triplets, '\0') + 1; } } diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index f546bb386f..e1b579de6b 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -243,7 +243,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, /* Finally the stringified UID value. */ memcpy (cp, buf, n); char *key_copy = cp + key_offset; - assert (key_copy == (char *) rawmemchr (cp, '\0') + 1); + assert (key_copy == strchr (cp, '\0') + 1); assert (cp == dataset->strdata + total - offsetof (struct dataset, strdata)); -- cgit 1.4.1