Skip to content

TEST_ASSERT_EQUAL_STRING / UnityAssertEqualString stops checking on first \0 for any string #407

@dueringa

Description

@dueringa

According to docs/UnityAssertionsReference.md, TEST_ASSERT_EQUAL_STRING

Asserts that the null terminated ('\0')strings are identical. If strings are of different lengths or any portion of the strings before their terminators differ, the assertion fails. Two NULL strings (i.e. zero length) are considered equivalent.

However, the "different length" part is not true currently, since the check goes (unity.c#L1263):

    for (i = 0; expected[i] || actual[i]; i++)

so if I compare foo with foo2, the test will not fail, although I'd expect it to.

TEST_ASSERT_EQUAL_STRING("foo", "foo2");
TEST_ASSERT_EQUAL_STRING("foo2", "foo");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions