1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-05-22 22:11:32 +00:00

Fix warning: -Wstring-compare

In file included from ../../../components/esm/defs.hpp:7,
                 from ../../../apps/components_tests/esm/test_fixed_string.cpp:1:
In function 'bool ESM::operator==(const FixedString<capacity>&, const char (&)[rhsSize]) [with long unsigned int capacity = 4; long unsigned int rhsSize = 12]',
    inlined from 'virtual void {anonymous}::EsmFixedString_empty_strings_Test::TestBody()' at ../../../apps/components_tests/esm/test_fixed_string.cpp:82:13:
../../../components/esm/esmcommon.hpp:142:85: error: 'int strncmp(const char*, const char*, size_t)' of strings of length 0 and 4 and bound of 4 evaluates to nonzero [-Werror=string-compare]
  142 |         return strnlen(rhs, rhsSize) == strnlen(lhs.mData, capacity) && std::strncmp(lhs.mData, rhs, capacity) == 0;
      |                                                                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
elsid 2025-04-26 00:02:05 +02:00
parent a5826b75e0
commit b5f8a0ecdb
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -74,19 +74,20 @@ namespace
TEST(EsmFixedString, empty_strings) TEST(EsmFixedString, empty_strings)
{ {
constexpr std::string_view someStr = "some string";
{ {
SCOPED_TRACE("4 bytes"); SCOPED_TRACE("4 bytes");
ESM::NAME empty = ESM::NAME(); ESM::NAME empty = ESM::NAME();
EXPECT_TRUE(empty == ""); EXPECT_TRUE(empty == "");
EXPECT_TRUE(empty == static_cast<uint32_t>(0)); EXPECT_TRUE(empty == static_cast<uint32_t>(0));
EXPECT_TRUE(empty != "some string"); EXPECT_TRUE(empty != someStr);
EXPECT_TRUE(empty != static_cast<uint32_t>(42)); EXPECT_TRUE(empty != static_cast<uint32_t>(42));
} }
{ {
SCOPED_TRACE("32 bytes"); SCOPED_TRACE("32 bytes");
ESM::NAME32 empty = ESM::NAME32(); ESM::NAME32 empty = ESM::NAME32();
EXPECT_TRUE(empty == ""); EXPECT_TRUE(empty == "");
EXPECT_TRUE(empty != "some string"); EXPECT_TRUE(empty != someStr);
} }
} }