mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 16:26:27 +08:00
Avoid dropping null byte in format string (#4732)
* Avoid dropping null byte in format string * Add a test for null byte in format string
This commit is contained in:
parent
4b50ad7944
commit
eeff8680ed
@ -2690,16 +2690,16 @@ template <typename... T> struct fstring {
|
|||||||
static_assert(count<(is_view<remove_cvref_t<T>>::value &&
|
static_assert(count<(is_view<remove_cvref_t<T>>::value &&
|
||||||
std::is_reference<T>::value)...>() == 0,
|
std::is_reference<T>::value)...>() == 0,
|
||||||
"passing views as lvalues is disallowed");
|
"passing views as lvalues is disallowed");
|
||||||
if (FMT_USE_CONSTEVAL) parse_format_string<char>(s, checker(s, arg_pack()));
|
if (FMT_USE_CONSTEVAL)
|
||||||
|
parse_format_string<char>(str, checker(str, arg_pack()));
|
||||||
constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
|
constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
|
||||||
(void)unused;
|
(void)unused;
|
||||||
}
|
}
|
||||||
template <typename S,
|
template <typename S,
|
||||||
FMT_ENABLE_IF(std::is_convertible<const S&, string_view>::value)>
|
FMT_ENABLE_IF(std::is_convertible<const S&, string_view>::value)>
|
||||||
FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) {
|
FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) {
|
||||||
auto sv = string_view(str);
|
|
||||||
if (FMT_USE_CONSTEVAL)
|
if (FMT_USE_CONSTEVAL)
|
||||||
detail::parse_format_string<char>(sv, checker(sv, arg_pack()));
|
detail::parse_format_string<char>(str, checker(str, arg_pack()));
|
||||||
constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
|
constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
|
||||||
(void)unused;
|
(void)unused;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -239,6 +239,16 @@ if (CMAKE_CXX_STANDARD GREATER_EQUAL 20)
|
|||||||
#endif
|
#endif
|
||||||
"
|
"
|
||||||
ERROR)
|
ERROR)
|
||||||
|
expect_compile(
|
||||||
|
format-string-embedded-nul-error
|
||||||
|
"
|
||||||
|
#if FMT_USE_CONSTEVAL
|
||||||
|
fmt::format(\"a\\0{}\");
|
||||||
|
#else
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
"
|
||||||
|
ERROR)
|
||||||
|
|
||||||
# Compile-time argument name check
|
# Compile-time argument name check
|
||||||
expect_compile(
|
expect_compile(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user