Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Jul 22, 2023
1 parent 19f7ff9 commit bd12c45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dev/Cpp/Effekseer/Effekseer/Utils/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FixedSizeString
FixedSizeString(const T* ptr)
{
size_t original_length = Traits::length(ptr);
size_ = std::min(data_.size() - 1, original_length);
size_ = std::min(data_.size(), original_length);
memcpy(data_.data(), ptr, size_ * sizeof(T));
data_[size_] = 0;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ class FixedSizeString
}

private:
std::array<T, N> data_;
std::array<T, N + 1> data_;
size_t size_;
};

Expand Down
16 changes: 16 additions & 0 deletions Dev/Cpp/Test/Runtime/String.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "../TestHelper.h"
#include <Effekseer.h>
#include <iostream>

#define TEST_EQUAL_STR(x, y) \
if ((x) != (y)) \
{ \
std::cout << "Test failed : " << __LINE__ << std::endl; \
abort(); \
}

void FixedSizeStringTest()
{
TEST_EQUAL_STR((std::u16string(u"1234")), (Effekseer::FixedSizeString<char16_t, 4>(u"12345").data()));
}

void StringAndPathHelperTest()
{
Expand Down Expand Up @@ -63,6 +76,9 @@ void StringAndPathHelperTest()

#if defined(__linux__) || defined(__APPLE__) || defined(WIN32)

TestRegister Runtime_FixedSizeStringTest("Runtime.FixedSizeStringTest", []() -> void
{ FixedSizeStringTest(); });

TestRegister Runtime_StringAndPathHelperTest("Runtime.StringAndPathHelperTest", []() -> void
{ StringAndPathHelperTest(); });

Expand Down

0 comments on commit bd12c45

Please sign in to comment.