1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

AK: Disallow returning of string literals for errors in kernel code

This code should not be used in the kernel - we should always propagate
proper errno codes in case we need to return those to userland so it
could decode it in a reasonable way.
This commit is contained in:
Liav A 2023-02-04 14:18:36 +02:00 committed by Linus Groh
parent 56b799c556
commit 048fb2c204
5 changed files with 51 additions and 20 deletions

View file

@ -684,9 +684,7 @@ struct Formatter<Error> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
{
#if defined(AK_OS_SERENITY) && defined(KERNEL)
if (error.is_errno())
return Formatter<FormatString>::format(builder, "Error(errno={})"sv, error.code());
return Formatter<FormatString>::format(builder, "Error({})"sv, error.string_literal());
return Formatter<FormatString>::format(builder, "Error(errno={})"sv, error.code());
#else
if (error.is_syscall())
return Formatter<FormatString>::format(builder, "{}: {} (errno={})"sv, error.string_literal(), strerror(error.code()), error.code());