mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:17:45 +00:00
AK: Explicitly calculate length of char* when printing
This moves out the calculation of the char* out to the formatter. Additionally, we now print (null) when a null pointer is passed.
This commit is contained in:
parent
52d017c611
commit
6eecc65787
2 changed files with 9 additions and 2 deletions
|
@ -395,6 +395,8 @@ template<>
|
|||
struct Formatter<Bytes> : Formatter<ReadonlyBytes> {
|
||||
};
|
||||
|
||||
// FIXME: Printing raw char pointers is inherently dangerous. Remove this and
|
||||
// its users and prefer StringView over it.
|
||||
template<>
|
||||
struct Formatter<char const*> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, char const* value)
|
||||
|
@ -403,7 +405,8 @@ struct Formatter<char const*> : Formatter<StringView> {
|
|||
Formatter<FlatPtr> formatter { *this };
|
||||
return formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
||||
}
|
||||
return Formatter<StringView>::format(builder, value);
|
||||
|
||||
return Formatter<StringView>::format(builder, value != nullptr ? StringView { value, __builtin_strlen(value) } : "(null)"sv);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue