fix UB in make_error_code(utf8_errc)
MODIFY
include/vcpkg/base/unicode.h
include/vcpkg/base/unicode.h
@@ -59,11 +59,7 @@ namespace vcpkg::Unicode
UnexpectedEof = 6,
};
- struct utf8_category : std::error_category
- {
- const char* name() const noexcept override;
- std::string message(int condition) const override;
- };
+ const std::error_category& utf8_category() noexcept;
inline std::error_code make_error_code(utf8_errc err) noexcept
{

MODIFY
src/vcpkg/base/unicode.cpp
src/vcpkg/base/unicode.cpp
@@ -113,8 +113,14 @@ namespace vcpkg::Unicode
return res;
}
- const char* utf8_category::name() const noexcept { return "utf8"; }
- std::string utf8_category::message(int condition) const
+ struct Utf8Category : std::error_category
+ {
+ const char* name() const noexcept override;
+ std::string message(int condition) const override;
+ };
+
+ const char* Utf8Category::name() const noexcept { return "utf8"; }
+ std::string Utf8Category::message(int condition) const
{
switch (static_cast<utf8_errc>(condition))
{
@@ -130,6 +136,12 @@ namespace vcpkg::Unicode
}
}
+ const std::error_category& utf8_category() noexcept
+ {
+ static const Utf8Category t;
+ return t;
+ }
+
Utf8Decoder::Utf8Decoder() noexcept : current_(end_of_file), next_(nullptr), last_(nullptr) { }
Utf8Decoder::Utf8Decoder(const char* first, const char* last) noexcept : current_(0), next_(first), last_(last)
{
@@ -255,7 +267,7 @@ namespace vcpkg::Unicode
next(ec);
if (ec)
{
- vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, ec.message());
+ vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "utf-8 error: %s", ec.message());
}
return *this;

fix UB in make_error_code(utf8_errc) (#18)