From 655ec9d94880cb7f3c5ff3bf4917705f7629b0d3 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 20 Jul 2023 17:14:12 +0200 Subject: [PATCH] Utils: Fix SmallString::contains Both strings are not null terminated. Change-Id: Ib9fb88925ef6ba261ae3c1ef69f0450935d31cc1 Reviewed-by: Tim Jenssen Reviewed-by: Qt CI Patch Build Bot --- src/libs/utils/smallstring.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h index 30d0dd746f8..bd4f708fed1 100644 --- a/src/libs/utils/smallstring.h +++ b/src/libs/utils/smallstring.h @@ -343,12 +343,10 @@ public: return BasicSmallString(utf8ByteArray.constData(), uint(utf8ByteArray.size())); } - // precondition: has to be null terminated bool contains(SmallStringView subStringToSearch) const { - const char *found = std::strstr(data(), subStringToSearch.data()); - - return found != nullptr; + return SmallStringView{*this}.find(subStringToSearch) + != SmallStringView::npos; } bool contains(char characterToSearch) const