From 94ebd2816ed1cbf08334573175d2ed1dec18f962 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 7 Nov 2022 11:21:27 +0100 Subject: fix use after free --- serialize/anim.cpp | 1 - serialize/anim.hpp | 6 +++--- serialize/magnum-vector2i.hpp | 5 ++--- serialize/string.cpp | 39 --------------------------------------- serialize/string.hpp | 27 --------------------------- serialize/tile-atlas.cpp | 3 +-- 6 files changed, 6 insertions(+), 75 deletions(-) delete mode 100644 serialize/string.cpp delete mode 100644 serialize/string.hpp (limited to 'serialize') diff --git a/serialize/anim.cpp b/serialize/anim.cpp index 9cafbfc0..79608de0 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -1,6 +1,5 @@ #include "serialize/magnum-vector2i.hpp" #include "serialize/anim.hpp" -#include "serialize/string.hpp" namespace floormat::Serialize { diff --git a/serialize/anim.hpp b/serialize/anim.hpp index 9d6db66c..fa6b6d22 100644 --- a/serialize/anim.hpp +++ b/serialize/anim.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -22,7 +22,7 @@ enum class anim_direction : unsigned char struct anim_group final { - String name; + std::string name; std::vector frames; Vector2ui ground; }; @@ -31,7 +31,7 @@ struct anim final { static constexpr int default_fps = 24; - String object_name, anim_name; + std::string object_name, anim_name; std::vector groups; Vector2ui pixel_size; std::size_t nframes = 0, width = 0, height = 0, fps = default_fps, actionframe = 0; diff --git a/serialize/magnum-vector2i.hpp b/serialize/magnum-vector2i.hpp index 7b78d73f..d1074b55 100644 --- a/serialize/magnum-vector2i.hpp +++ b/serialize/magnum-vector2i.hpp @@ -1,8 +1,7 @@ #include "compat/assert.hpp" -#include "serialize/string.hpp" #include +#include #include -#include #include namespace nlohmann { @@ -21,7 +20,7 @@ struct adl_serializer> final } static void from_json(const json& j, Magnum::Math::Vector2& val) { - Corrade::Containers::StringView str = j; + std::string str = j; using type = std::conditional_t, std::intmax_t, std::uintmax_t>; constexpr auto format_string = std::is_signed_v ? "%jd x %jd%n" : "%ju x %ju%n"; type x = 0, y = 0; diff --git a/serialize/string.cpp b/serialize/string.cpp deleted file mode 100644 index 0c0fa74e..00000000 --- a/serialize/string.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "string.hpp" -#include -#include -#include - -using String = Corrade::Containers::String; -using StringView = Corrade::Containers::StringView; - -namespace nlohmann { - -void adl_serializer::to_json(json& j, const String& val) -{ - using nlohmann::to_json; - to_json(j, std::string_view { val.cbegin(), val.cend() }); -} - -void adl_serializer::from_json(const json& j, String& val) -{ - using nlohmann::from_json; - std::string_view str; - from_json(j, str); - val = { str.cbegin(), str.size() }; -} - -void adl_serializer::to_json(json& j, const StringView& val) -{ - using nlohmann::to_json; - to_json(j, std::string_view { val.cbegin(), val.cend() }); -} - -void adl_serializer::from_json(const json& j, StringView& val) -{ - using nlohmann::from_json; - std::string_view str; - from_json(j, str); - val = { str.cbegin(), str.size() }; -} - -} // namespace nlohmann diff --git a/serialize/string.hpp b/serialize/string.hpp deleted file mode 100644 index 66e448a4..00000000 --- a/serialize/string.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -namespace Corrade::Containers { - -template class BasicStringView; -class String; -using StringView = BasicStringView; - -} // namespace Corrade::Containers - -namespace nlohmann { - -template<> -struct adl_serializer { - static void to_json(json& j, const Corrade::Containers::String& val); - static void from_json(const json& j, Corrade::Containers::String& val); -}; - -template<> -struct adl_serializer { - static void to_json(json& j, const Corrade::Containers::StringView& val); - static void from_json(const json& j, Corrade::Containers::StringView& val); -}; - -} // namespace nlohmann diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index 711d5fdd..8caaedd3 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -1,7 +1,6 @@ #include "src/tile-atlas.hpp" #include "serialize/tile-atlas.hpp" #include "serialize/magnum-vector2i.hpp" -#include "serialize/string.hpp" #include "loader.hpp" #include @@ -11,7 +10,7 @@ using namespace floormat; namespace nlohmann { -using proxy_atlas = std::tuple; +using proxy_atlas = std::tuple; void adl_serializer>::to_json(json& j, const std::shared_ptr& x) { -- cgit v1.2.3