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

AK+Everywhere: Disallow Error::from_string_view(FooString)

That pattern seems to show up a lot in code written by people that
aren't intimately familiar with the lifetime model of Error and Strings.
This commit makes the compiler detect it and present a more helpful
diagnostic than "garbage string at runtime".
This commit is contained in:
Ali Mohammad Pur 2023-04-27 21:21:19 +03:30 committed by Andreas Kling
parent cc35bab143
commit 7e6341587b
7 changed files with 29 additions and 14 deletions

View file

@ -12,11 +12,16 @@
#include <LibCrypto/ASN1/DER.h>
#include <LibCrypto/ASN1/PEM.h>
namespace {
static String s_error_string;
}
namespace TLS {
#define ERROR_WITH_SCOPE(error) \
do { \
return Error::from_string_view(TRY(String::formatted("{}: {}", current_scope, error))); \
#define ERROR_WITH_SCOPE(error) \
do { \
s_error_string = TRY(String::formatted("{}: {}", current_scope, error)); \
return Error::from_string_view(s_error_string.bytes_as_string_view()); \
} while (0)
#define ENTER_TYPED_SCOPE(tag_kind_name, scope) \
@ -77,7 +82,7 @@ static ErrorOr<SupportedGroup> oid_to_curve(Vector<int> curve)
else if (curve == curve_prime256)
return SupportedGroup::SECP256R1;
return Error::from_string_view(TRY(String::formatted("Unknown curve oid {}", curve)));
return Error::from_string_view("Unknown curve oid"sv);
}
static ErrorOr<Crypto::UnsignedBigInteger> parse_version(Crypto::ASN1::Decoder& decoder, Vector<StringView> current_scope)