From d9f2deffbc13b115292ea4da3517d8888f3a4aaf Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 9 Mar 2023 15:51:57 -0800 Subject: [PATCH] Checking indices before dereference --- api/include/opentelemetry/common/string_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/common/string_util.h b/api/include/opentelemetry/common/string_util.h index 5496f8579e..6dce79f1ba 100644 --- a/api/include/opentelemetry/common/string_util.h +++ b/api/include/opentelemetry/common/string_util.h @@ -14,11 +14,11 @@ class StringUtil public: static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept { - while (str[static_cast(left)] == ' ' && left <= right) + while (left <= right && str[static_cast(left)] == ' ') { left++; } - while (str[static_cast(right)] == ' ' && left <= right) + while (left <= right && str[static_cast(right)] == ' ') { right--; }