Skip to content

Commit

Permalink
Merge branch 'esm_name_template_fix' into 'master'
Browse files Browse the repository at this point in the history
Make sure that proper operator function of ESM:FIXED_STRING is used for char[N] argument

See merge request OpenMW/openmw!63
  • Loading branch information
psi29a committed Feb 23, 2019
2 parents 3a1a241 + 57cc2ec commit 4a69d96
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
36 changes: 36 additions & 0 deletions apps/openmw_test_suite/esm/test_fixed_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@ TEST(EsmFixedString, operator__eq_ne)
EXPECT_TRUE(name == ss);
}
}
TEST(EsmFixedString, operator__eq_ne_const)
{
{
SCOPED_TRACE("asdc == asdc (const)");
ESM::NAME name;
name.assign("asdc");
const char s[4] = { 'a', 's', 'd', 'c' };
std::string ss(s, 4);

EXPECT_TRUE(name == s);
EXPECT_TRUE(name == ss.c_str());
EXPECT_TRUE(name == ss);
}
{
SCOPED_TRACE("asdc == asdcx (const)");
ESM::NAME name;
name.assign("asdc");
const char s[5] = { 'a', 's', 'd', 'c', 'x' };
std::string ss(s, 5);

EXPECT_TRUE(name != s);
EXPECT_TRUE(name != ss.c_str());
EXPECT_TRUE(name != ss);
}
{
SCOPED_TRACE("asdc == asdc[NULL] (const)");
ESM::NAME name;
name.assign("asdc");
const char s[5] = { 'a', 's', 'd', 'c', '\0' };
std::string ss(s, 5);

EXPECT_TRUE(name == s);
EXPECT_TRUE(name == ss.c_str());
EXPECT_TRUE(name == ss);
}
}

TEST(EsmFixedString, empty_strings)
{
Expand Down
5 changes: 4 additions & 1 deletion components/esm/esmcommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class FIXED_STRING_BASE
return false;
return std::strncmp(self()->ro_data(), str, size) == 0;
}
bool operator==(const char* const str) const

//this operator will not be used for char[N], only for char*
template<typename T, typename = typename std::enable_if<std::is_same<T, char>::value>::type>
bool operator==(const T* const& str) const
{
char const* const data = self()->ro_data();
for(size_t i = 0; i < size; ++i)
Expand Down

0 comments on commit 4a69d96

Please sign in to comment.