From f453059448d883c1a54b2b53147715de38f872f4 Mon Sep 17 00:00:00 2001 From: Fu Juntang <StrongTiger_001@163.com> Date: 星期一, 06 九月 2021 19:11:57 +0800 Subject: [PATCH] Fix the return condition. --- src/bh_api.cpp | 88 +++++++++++++++++++++---------------------- 1 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/bh_api.cpp b/src/bh_api.cpp index 5b24903..438530e 100644 --- a/src/bh_api.cpp +++ b/src/bh_api.cpp @@ -154,30 +154,29 @@ memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + return false; } #if defined(PRO_DE_SERIALIZE) - ::bhome_msg::MsgCommonReply mcr; - mcr.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); - mcr.mutable_errmsg()->set_errstring(errString); - *reply_len = mcr.ByteSizeLong(); - *reply = malloc(*reply_len); - mcr.SerializePartialToArray(*reply, *reply_len); + ::bhome_msg::MsgCommonReply mcr; + mcr.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); + mcr.mutable_errmsg()->set_errstring(errString); + *reply_len = mcr.ByteSizeLong(); + *reply = malloc(*reply_len); + mcr.SerializePartialToArray(*reply, *reply_len); #else - min = strlen(errString) + 1; - buf = malloc(min) ; - memcpy(buf, errString, strlen(errString)); - *((char *)buf + min - 1) = '\0'; - - *reply = buf; - *reply_len = min; + min = strlen(errString) + 1; + buf = malloc(min) ; + memcpy(buf, errString, strlen(errString)); + *((char *)buf + min - 1) = '\0'; + + *reply = buf; + *reply_len = min; #endif - - if (rv == 0) - return true; - return false; + return true; + } int BHUnregister(const void *proc_info, const int proc_info_len, void **reply, int *reply_len, const int timeout_ms) @@ -256,6 +255,8 @@ rv = EBUS_RES_BUSY; memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + + return false; } #if defined(PRO_DE_SERIALIZE) @@ -275,10 +276,8 @@ *reply_len = min; #endif - if (rv == 0) - return true; - - return false; + return true; + } int BHRegisterTopics(const void *topics, const int topics_len, void **reply, int *reply_len, const int timeout_ms) @@ -392,6 +391,8 @@ rv = EBUS_RES_BUSY; memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + + return false; } #if defined(PRO_DE_SERIALIZE) @@ -411,10 +412,8 @@ *reply_len = len; #endif - if (rv == 0) - return true; + return true; - return false; } int BHQueryTopicAddress(const void *remote, const int remote_len, const void *topic, const int topic_len, void **reply, int *reply_len, const int timeout_ms) @@ -499,6 +498,8 @@ rv = EBUS_RES_BUSY; memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + + return false; } #if defined(PRO_DE_SERIALIZE) @@ -565,10 +566,8 @@ #endif - if (rv == 0) - return true; + return true; - return false; } int BHQueryProcs(const void *remote, const int remote_len, const void *query, const int query_len, void **reply, int *reply_len, const int timeout_ms) @@ -646,6 +645,8 @@ rv = EBUS_RES_BUSY; memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + + return false; } #if defined(PRO_DE_SERIALIZE) @@ -730,10 +731,7 @@ } #endif - if (rv == 0) - return true; - - return false; + return true; } @@ -860,6 +858,8 @@ rv = EBUS_RES_BUSY; memset(errString, 0x00, sizeof(errString)); strncpy(errString, bus_strerror(rv), sizeof(errString)); + + return false; } #if defined(PRO_DE_SERIALIZE) @@ -879,10 +879,7 @@ *reply_len = len; #endif - if (rv == 0) - return true; - - return false; + return true; } @@ -1521,7 +1518,6 @@ free(buf); - printf("BHRequest finished_7\n"); } pthread_mutex_unlock(&mutex); @@ -1533,16 +1529,18 @@ strncpy(errString, bus_strerror(rv), sizeof(errString)); } -#if defined(PRO_DE_SERIALIZE) - ::bhome_msg::MsgRequestTopicReply mrt; - mrt.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); - mrt.mutable_errmsg()->set_errstring(errString); - mrt.set_data(rr.data.data()); - *reply_len = mrt.ByteSizeLong(); - *reply = malloc(*reply_len); - mrt.SerializePartialToArray(*reply, *reply_len); +#if defined(PRO_DE_SERIALIZE) + if (rv == 0) { + ::bhome_msg::MsgRequestTopicReply mrt; + mrt.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv)); + mrt.mutable_errmsg()->set_errstring(errString); + mrt.set_data(rr.data.data()); + *reply_len = mrt.ByteSizeLong(); + *reply = malloc(*reply_len); + mrt.SerializePartialToArray(*reply, *reply_len); + } #else - if (rv > 0) { + if (rv == 0) { min = strlen(errString) + 1; buf = malloc(min); memcpy(buf, errString, strlen(errString)); -- Gitblit v1.8.0