shortrange: Fix potential NULL pointer dereference
@@ -753,17 +753,18 @@ int32_t uShortRangeSetIpConnectionStatusCallback(int32_t shortRangeHandle,
if (gUShortRangePrivateMutex != NULL) {
pInstance = pUShortRangePrivateGetInstance(shortRangeHandle);
errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER;
- if (pInstance != NULL && pCallback != NULL) {
+ if (pInstance != NULL) {
+ errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
+ if (pCallback != NULL) {
pInstance->pIpConnectionStatusCallback = pCallback;
pInstance->pIpConnectionStatusCallbackParameter = pCallbackParameter;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
- } else if (pInstance != NULL && pCallback == NULL) {
+ } else {
pInstance->pIpConnectionStatusCallback = NULL;
pInstance->pIpConnectionStatusCallbackParameter = NULL;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
}
configureConnectionUrcHandlers(pInstance);
}
+ }
return errorCode;
}
@@ -778,17 +779,18 @@ int32_t uShortRangeSetBtConnectionStatusCallback(int32_t shortRangeHandle,
if (gUShortRangePrivateMutex != NULL) {
pInstance = pUShortRangePrivateGetInstance(shortRangeHandle);
errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER;
- if (pInstance != NULL && pCallback != NULL) {
+ if (pInstance != NULL) {
+ errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
+ if (pCallback != NULL) {
pInstance->pBtConnectionStatusCallback = pCallback;
pInstance->pBtConnectionStatusCallbackParameter = pCallbackParameter;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
- } else if (pInstance != NULL && pCallback == NULL) {
+ } else {
pInstance->pBtConnectionStatusCallback = NULL;
pInstance->pBtConnectionStatusCallbackParameter = NULL;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
}
configureConnectionUrcHandlers(pInstance);
}
+ }
return errorCode;
}
@@ -803,17 +805,18 @@ int32_t uShortRangeSetMqttConnectionStatusCallback(int32_t shortRangeHandle,
if (gUShortRangePrivateMutex != NULL) {
pInstance = pUShortRangePrivateGetInstance(shortRangeHandle);
errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER;
- if (pInstance != NULL && pCallback != NULL) {
+ if (pInstance != NULL) {
+ errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
+ if (pCallback != NULL) {
pInstance->pMqttConnectionStatusCallback = pCallback;
pInstance->pMqttConnectionStatusCallbackParameter = pCallbackParameter;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
- } else if (pInstance != NULL && pCallback == NULL) {
+ } else {
pInstance->pMqttConnectionStatusCallback = NULL;
pInstance->pMqttConnectionStatusCallbackParameter = NULL;
- errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;
}
configureConnectionUrcHandlers(pInstance);
}
+ }
return errorCode;
}
