Use std::char_traits<char>::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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N5NasAgbDGG28MqXjQvLqp
Signed-off-by: Claude <noreply@anthropic.com>
This commit is contained in:
Claude committed 2026-11-02 05:39:29 +00:00
1 parent 3720e4b3aa
commit e96469f783
2 files changed
+4 -4

No files matched your search

@@ -15,7 +15,7 @@
#include <cstddef> // size_t, ptrdiff_t
#include <cstdint> // uint8_t
#include <cstdio> // snprintf
#include <cstring> // memcpy, memset, strlen
#include <cstring> // memcpy, memset
#include <iterator> // next
#include <limits> // numeric_limits
#include <string> // 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<char>::length(decimal_point);
// convert decimal point to '.'
if (decimal_point_len != 0 && !(decimal_point_len == 1 && decimal_point[0] == '.'))