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--; }