diff --git a/apps/openmw_test_suite/esm/test_fixed_string.cpp b/apps/openmw_test_suite/esm/test_fixed_string.cpp index dc88a5f63..bd598cc93 100644 --- a/apps/openmw_test_suite/esm/test_fixed_string.cpp +++ b/apps/openmw_test_suite/esm/test_fixed_string.cpp @@ -97,7 +97,6 @@ TEST(EsmFixedString, struct_size) ASSERT_EQ(4, sizeof(ESM::NAME)); ASSERT_EQ(32, sizeof(ESM::NAME32)); ASSERT_EQ(64, sizeof(ESM::NAME64)); - ASSERT_EQ(256, sizeof(ESM::NAME256)); } TEST(EsmFixedString, is_pod) @@ -105,5 +104,4 @@ TEST(EsmFixedString, is_pod) ASSERT_TRUE(std::is_pod::value); ASSERT_TRUE(std::is_pod::value); ASSERT_TRUE(std::is_pod::value); - ASSERT_TRUE(std::is_pod::value); } diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index f7a8bf126..232a24fcf 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -6,7 +6,6 @@ #include #include -#include namespace ESM { @@ -57,11 +56,16 @@ public: } bool operator!=(const std::string& str) const { return !( (*this) == str ); } - size_t data_size() const { return size; } + static size_t data_size() { return size; } size_t length() const { return strnlen(self()->ro_data(), size); } std::string toString() const { return std::string(self()->ro_data(), this->length()); } - void assign(const std::string& value) { std::strncpy(self()->rw_data(), value.c_str(), size); } + void assign(const std::string& value) + { + std::strncpy(self()->rw_data(), value.c_str(), size-1); + self()->rw_data()[size-1] = '\0'; + } + void clear() { this->assign(""); } private: DERIVED const* self() const @@ -103,6 +107,20 @@ struct FIXED_STRING<4> : public FIXED_STRING_BASE bool operator==(uint32_t v) const { return v == intval; } bool operator!=(uint32_t v) const { return v != intval; } + void assign(const std::string& value) + { + intval = 0; + size_t length = value.size(); + if (length == 0) return; + data[0] = value[0]; + if (length == 1) return; + data[1] = value[1]; + if (length == 2) return; + data[2] = value[2]; + if (length == 3) return; + data[3] = value[3]; + } + char const* ro_data() const { return data; } char* rw_data() { return data; } }; @@ -110,7 +128,6 @@ struct FIXED_STRING<4> : public FIXED_STRING_BASE typedef FIXED_STRING<4> NAME; typedef FIXED_STRING<32> NAME32; typedef FIXED_STRING<64> NAME64; -typedef FIXED_STRING<256> NAME256; /* This struct defines a file 'context' which can be saved and later restored by an ESMReader instance. It will save the position within