From e96469f7835d62f200f3eee68e259cbc078885c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 05:39:29 +0000 Subject: [PATCH] Use std::char_traits::length instead of strlen in dump_float() Codacy (flawfinder, CWE-126) flags strlen on the locale's decimal point. The string is NUL-terminated by localeconv(), so the behavior is the same. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01N5NasAgbDGG28MqXjQvLqp Signed-off-by: Claude --- include/nlohmann/detail/output/serializer.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 597bb7f7d..18643c8cc 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -15,7 +15,7 @@ #include // size_t, ptrdiff_t #include // uint8_t #include // snprintf -#include // memcpy, memset, strlen +#include // memcpy, memset #include // next #include // numeric_limits #include // string, char_traits @@ -2102,7 +2102,7 @@ class serializer const auto* loc = std::localeconv(); JSON_ASSERT(loc != nullptr); const char* const decimal_point = (loc->decimal_point == nullptr) ? "" : loc->decimal_point; - const std::size_t decimal_point_len = std::strlen(decimal_point); + const std::size_t decimal_point_len = std::char_traits::length(decimal_point); // convert decimal point to '.' if (decimal_point_len != 0 && !(decimal_point_len == 1 && decimal_point[0] == '.')) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 056596771..60c0643c6 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -33480,7 +33480,7 @@ NLOHMANN_JSON_NAMESPACE_END #include // size_t, ptrdiff_t #include // uint8_t #include // snprintf -#include // memcpy, memset, strlen +#include // memcpy, memset #include // next #include // numeric_limits #include // string, char_traits @@ -37349,7 +37349,7 @@ class serializer const auto* loc = std::localeconv(); JSON_ASSERT(loc != nullptr); const char* const decimal_point = (loc->decimal_point == nullptr) ? "" : loc->decimal_point; - const std::size_t decimal_point_len = std::strlen(decimal_point); + const std::size_t decimal_point_len = std::char_traits::length(decimal_point); // convert decimal point to '.' if (decimal_point_len != 0 && !(decimal_point_len == 1 && decimal_point[0] == '.'))