This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch hotfix/coverity_fix in repository https://gitbox.apache.org/repos/asf/celix.git
commit 447c6cffeed0763d6e33e7313f87ba74a39ad811 Author: PengZheng <[email protected]> AuthorDate: Mon Apr 10 16:50:36 2023 +0800 Fix Coverity 211197 Dereference after null check. --- libs/framework/src/bundle_context.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c index 8f9cfa82..3e43531d 100644 --- a/libs/framework/src/bundle_context.c +++ b/libs/framework/src/bundle_context.c @@ -266,17 +266,13 @@ celix_status_t bundleContext_ungetServiceReference(bundle_context_pt context, se } celix_status_t bundleContext_getService(bundle_context_pt context, service_reference_pt reference, void** service_instance) { - celix_status_t status = CELIX_SUCCESS; - if (context != NULL && reference != NULL && service_instance != NULL && bundleContext_IsServiceReferenceValid(context, reference)) { - /*NOTE argument service_instance should be considered a 'const void**'. - To ensure backwards compatibility a cast is made instead. - */ - status = serviceReference_getService(reference, (const void**) service_instance); - } else { - status = CELIX_ILLEGAL_ARGUMENT; + if (context == NULL || reference == NULL || service_instance == NULL || !bundleContext_IsServiceReferenceValid(context, reference)) { + return CELIX_ILLEGAL_ARGUMENT; } - framework_logIfError(context->framework->logger, status, NULL, "Failed to get service"); - return status; + /*NOTE argument service_instance should be considered a 'const void**'. + To ensure backwards compatibility a cast is made instead. + */ + return serviceReference_getService(reference, (const void**) service_instance); } celix_status_t bundleContext_ungetService(bundle_context_pt context, service_reference_pt reference, bool *result) {
