diff --git a/Code/Framework/AzCore/AzCore/std/string/string_view.h b/Code/Framework/AzCore/AzCore/std/string/string_view.h index 9a98795554..4ded44644f 100644 --- a/Code/Framework/AzCore/AzCore/std/string/string_view.h +++ b/Code/Framework/AzCore/AzCore/std/string/string_view.h @@ -7,7 +7,6 @@ */ #pragma once -#include #include #include @@ -46,6 +45,10 @@ namespace AZStd return npos; } size_t foundIndex = searchIndex + charFindIndex; + if (foundIndex + count > size) + { + return npos; // the rest of the string doesnt fit in the remainder of the data buffer + } if (Traits::compare(&data[foundIndex], ptr, count) == 0) { return foundIndex; diff --git a/Code/Framework/AzCore/Tests/AZStd/String.cpp b/Code/Framework/AzCore/Tests/AZStd/String.cpp index 9dae4a3d3f..a88de48b9b 100644 --- a/Code/Framework/AzCore/Tests/AZStd/String.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/String.cpp @@ -1458,17 +1458,17 @@ namespace UnitTest constexpr double v15 = 0; constexpr const char* v16 = "Hello"; constexpr const wchar_t* v17 = L"Hello"; - constexpr void* v18 = 0; + constexpr void* v18 = nullptr; // This shouldn't give a compile error AZStd::string::format( - "%i %c %uc %c %c %i %i %u %i %lu %li %llu %lli %f %f %s %ls %p", + "%i %c %uc %hc %lc %i %i %u %i %lu %li %llu %lli %f %f %hs %ls %p", v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18); // This shouldn't give a compile error AZStd::wstring::format( - L"%i %c %uc %c %lc %i %i %u %i %lu %li %llu %lli %f %f %s %ls %p", - v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18); + L"%i %c %uc %hc %lc %i %i %u %i %lu %li %llu %lli %f %f %hs %ls %p", + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18); class WrappedInt {