This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch hotfix/utils_coverity_fix in repository https://gitbox.apache.org/repos/asf/celix.git
commit a027f6dfd1b77b35be1196f264dab0c3694ea107 Author: PengZheng <[email protected]> AuthorDate: Tue Apr 25 21:51:14 2023 +0800 Fix Coverity 211184 Dereference after null check. --- libs/utils/private/test/version_test.cpp | 7 +++++++ libs/utils/src/version.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/libs/utils/private/test/version_test.cpp b/libs/utils/private/test/version_test.cpp index 1fa59e71..e167576b 100644 --- a/libs/utils/private/test/version_test.cpp +++ b/libs/utils/private/test/version_test.cpp @@ -379,6 +379,13 @@ TEST(version,semanticCompatibility) { LONGS_EQUAL(CELIX_SUCCESS, status); version_createVersion(2, 3, 5, NULL, &provider); + status = version_isCompatible(NULL, provider, &isCompatible); + CHECK(isCompatible == false); + LONGS_EQUAL(CELIX_SUCCESS, status); + status = version_isCompatible(provider, NULL, &isCompatible); + CHECK(isCompatible == false); + LONGS_EQUAL(CELIX_SUCCESS, status); + version_createVersion(2, 1, 9, NULL, &compatible_user); version_createVersion(1, 3, 5, NULL, &incompatible_user_by_major); version_createVersion(2, 5, 7, NULL, &incompatible_user_by_minor); diff --git a/libs/utils/src/version.c b/libs/utils/src/version.c index 6c243ab5..a8385fd1 100644 --- a/libs/utils/src/version.c +++ b/libs/utils/src/version.c @@ -293,6 +293,8 @@ char* celix_version_toString(const celix_version_t* version) { bool celix_version_isCompatible(const celix_version_t* user, const celix_version_t* provider) { if (user == NULL && provider == NULL) { return true; + } else if (user == NULL || provider == NULL) { + return false; } else { return celix_version_isUserCompatible(user, provider->major, provider->minor); }
