aboutsummaryrefslogtreecommitdiff
path: root/nscd
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2023-02-03 12:01:33 +0000
committerWilco Dijkstra <wilco.dijkstra@arm.com>2023-02-06 16:16:19 +0000
commit32c7acd46401530fdbd4e98508c9baaa705f8b53 (patch)
tree000fcd17f9b6ddbc14af397f33963e72a3c9d4bb /nscd
parentd2d3f3720ce627a4fe154d8dd14db716a32bcc6e (diff)
downloadglibc-32c7acd46401530fdbd4e98508c9baaa705f8b53.zip
glibc-32c7acd46401530fdbd4e98508c9baaa705f8b53.tar.gz
glibc-32c7acd46401530fdbd4e98508c9baaa705f8b53.tar.bz2
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 <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nscd')
-rw-r--r--nscd/connections.c2
-rw-r--r--nscd/grpcache.c2
-rw-r--r--nscd/netgroupcache.c12
-rw-r--r--nscd/pwdcache.c2
4 files changed, 9 insertions, 9 deletions
diff --git a/nscd/connections.c b/nscd/connections.c
index b5fbb1a..b1231a9 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 eb20c4f..cdd1071 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 439dd4b..06b7d7b 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 f546bb3..e1b579d 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));