]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: improve problematic_chars function
authorJim Meyering <meyering@meta.com>
Fri, 14 Jul 2023 05:29:52 +0000 (22:29 -0700)
committerJim Meyering <meyering@meta.com>
Fri, 14 Jul 2023 05:39:04 +0000 (22:39 -0700)
* src/digest.c (problematic_chars): Implement using strcspn,
and traversing S only once, rather than once per escaped byte.

src/digest.c

index e80eb3406a9b2c74bc531de076bba9c6fd9cccbd..60ba82e5f9f31e0d342b18dce3cdafe56086f6c7 100644 (file)
@@ -568,7 +568,8 @@ ATTRIBUTE_PURE
 static bool
 problematic_chars (char const *s)
 {
-  return strchr (s, '\\') || strchr (s, '\n') || strchr (s, '\r');
+  size_t length = strcspn (s, "\\\n\r");
+  return s[length] != '\0';
 }
 
 #define ISWHITE(c) ((c) == ' ' || (c) == '\t')