diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 169012e0..d598ffe2 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -861,7 +861,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 47861346..1b7190a1 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15494,7 +15494,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; }