From c759a73cedf4566e537506e4e4aed4403970724d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 16 Oct 2026 09:55:34 +0200 Subject: [PATCH] Mask the JSON pointer hash constants without a cast to uint64_t The cast is useless where size_t is uint64_t (GCC -Wuseless-cast); the mask alone already keeps the constants in size_t's range. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 5 ++--- single_include/nlohmann/json.hpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 41d5acbde..63ab49f7d 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -12,7 +12,6 @@ #include // isdigit #include // errno, ERANGE #include // size_t -#include // uint64_t #include // strtoull #ifndef JSON_NO_IO #include // ostream @@ -531,10 +530,10 @@ class json_pointer static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept { - std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & static_cast((std::numeric_limits::max)())); + std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & (std::numeric_limits::max)()); for (std::size_t i = 0; i < token.size(); ++i) { - h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & static_cast((std::numeric_limits::max)())); + h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & (std::numeric_limits::max)()); } return h ^ (h >> 29u); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2b5a20f77..0db7d067a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20978,7 +20978,6 @@ NLOHMANN_JSON_NAMESPACE_END #include // isdigit #include // errno, ERANGE #include // size_t -#include // uint64_t #include // strtoull #ifndef JSON_NO_IO #include // ostream @@ -21504,10 +21503,10 @@ class json_pointer static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept { - std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & static_cast((std::numeric_limits::max)())); + std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & (std::numeric_limits::max)()); for (std::size_t i = 0; i < token.size(); ++i) { - h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & static_cast((std::numeric_limits::max)())); + h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & (std::numeric_limits::max)()); } return h ^ (h >> 29u); }