mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-02 06:20:09 +00:00
Wrap Char in array to avoid pointer arithmetic (#3695)
This resolves the following finding reported by Coverity Static Analysis v2023.6.1 on line 1964 of fmt/include/fmt/format.h: ptr_arith: Using &v as an array. This might corrupt or misinterpret adjacent memory locations.
This commit is contained in:
parent
19276d7325
commit
e0d3e346d2
@ -1958,11 +1958,12 @@ auto write_escaped_string(OutputIt out, basic_string_view<Char> str)
|
||||
|
||||
template <typename Char, typename OutputIt>
|
||||
auto write_escaped_char(OutputIt out, Char v) -> OutputIt {
|
||||
Char v_array[1] = {v};
|
||||
*out++ = static_cast<Char>('\'');
|
||||
if ((needs_escape(static_cast<uint32_t>(v)) && v != static_cast<Char>('"')) ||
|
||||
v == static_cast<Char>('\'')) {
|
||||
out = write_escaped_cp(
|
||||
out, find_escape_result<Char>{&v, &v + 1, static_cast<uint32_t>(v)});
|
||||
out, find_escape_result<Char>{v_array, v_array + 1, static_cast<uint32_t>(v)});
|
||||
} else {
|
||||
*out++ = v;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user