From c294eaacc1b365dfc1ef177a865c5d4c7e69d657 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Fri, 3 Nov 2023 00:40:17 +0100 Subject: [PATCH] Fix: char_traits::find needs to return nullptr if nothing was found. --- src/string.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/string.cpp b/src/string.cpp index 7e8870b795..7e54b63912 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -343,12 +343,12 @@ struct CaseInsensitiveCharTraits : public std::char_traits { return 0; } - static const char *find(const char *s, int n, char a) + static const char *find(const char *s, size_t n, char a) { - while (n-- > 0 && toupper(*s) != toupper(a)) { - ++s; + for (; n > 0; --n, ++s) { + if (toupper(*s) == toupper(a)) return s; } - return s; + return nullptr; } };