Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ut-core: Minor Bug In Macro, string length is not checked #124

Open
Ulrond opened this issue Nov 4, 2024 · 0 comments
Open

ut-core: Minor Bug In Macro, string length is not checked #124

Ulrond opened this issue Nov 4, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Ulrond
Copy link
Contributor

Ulrond commented Nov 4, 2024

Possible bug, do we need to check the length of the two strings during the comparison

Example of the problem.

Validation String: "ABC"
Input String: "ABCDEF"

I think this will pass as the Validation String == Input String, when actually it should fail.

/**! Asserts that a string KVP field matches the expected value. */
#define UT_ASSERT_KVP_EQUAL_PROFILE_STRING(checkValue, key) \
    { \
        char result_kvp[UT_KVP_MAX_ELEMENT_SIZE]={0}; \
        ut_kvp_status_t status; \
        status = ut_kvp_getStringField(ut_kvp_profile_getInstance(), key, result_kvp, UT_KVP_MAX_ELEMENT_SIZE); \
        UT_ASSERT( status == UT_KVP_STATUS_SUCCESS ); \
        if ( status == UT_KVP_STATUS_SUCCESS ) \
        { \
            UT_ASSERT_STRING_EQUAL(checkValue, result_kvp); \
        } \
        else \
        { \
            UT_ASSERT(true);\
        } \
    }

Code that performs the validation is here, we may need to upgrade all the string macros to validate better

#define UT_ASSERT_STRING_EQUAL(expected, actual)                       \
    {                                                                  \
        const char *_expected = (const char *)(expected);              \
        const char *_actual = (const char *)(actual);                  \
        const int _result = strcmp(_actual, _expected);                \
        if (_result)                                                   \
        {                                                              \
            UT_LOG_ASSERT(UT_ASSERT_STRING_EQUAL, #actual, #expected); \
        }                                                              \
        CU_ASSERT_STRING_EQUAL(_actual, _expected);                    \
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants