diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 0a4ddbda..c6f217cb 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -807,7 +807,9 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - state = utf8d[256u + state * 16u + type]; + std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + assert(0 <= index and index < 400); + state = utf8d[index]; return state; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 68916fa0..8089e9fa 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14552,7 +14552,9 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - state = utf8d[256u + state * 16u + type]; + std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + assert(0 <= index and index < 400); + state = utf8d[index]; return state; }