Merge pull request #614 from fengzeroz/main

fix: cppcheck warning
This commit is contained in:
fengzeroz
2022-07-04 17:17:30 +08:00
committed by GitHub
11 changed files with 22 additions and 32 deletions
+2 -2
View File
@@ -45,7 +45,7 @@ int modbus_tag_to_point(neu_datatag_t *tag, modbus_point_t *point)
}
char area = 0;
int n = sscanf(tag->address, "%hhd!%c%hd", &point->slave_id, &area,
int n = sscanf(tag->address, "%hhu!%c%hu", &point->slave_id, &area,
&point->start_address);
if (n != 3) {
return NEU_ERR_TAG_ADDRESS_FORMAT_INVALID;
@@ -153,7 +153,7 @@ int modbus_tag_to_point(neu_datatag_t *tag, modbus_point_t *point)
}
strncpy(point->name, tag->name, sizeof(point->name));
return 0;
return ret;
}
modbus_read_cmd_sort_t *modbus_tag_sort(UT_array *tags, uint16_t max_byte)
+4 -7
View File
@@ -57,8 +57,6 @@ int modbus_send_msg(void *ctx, uint16_t n_byte, uint8_t *bytes)
int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
uint16_t max_byte)
{
int ret = 0;
if (group->user_data == NULL) {
struct modbus_group_data *gd =
calloc(1, sizeof(struct modbus_group_data));
@@ -69,8 +67,8 @@ int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
utarray_foreach(group->tags, neu_datatag_t *, tag)
{
modbus_point_t *p = calloc(1, sizeof(modbus_point_t));
ret = modbus_tag_to_point(tag, p);
modbus_point_t *p = calloc(1, sizeof(modbus_point_t));
int ret = modbus_tag_to_point(tag, p);
assert(ret == 0);
utarray_push_back(gd->tags, &p);
@@ -84,7 +82,7 @@ int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
for (uint16_t i = 0; i < gd->cmd_sort->n_cmd; i++) {
uint16_t response_size = 0;
ret = modbus_stack_read(
int ret = modbus_stack_read(
plugin->stack, gd->cmd_sort->cmd[i].slave_id,
gd->cmd_sort->cmd[i].area, gd->cmd_sort->cmd[i].start_address,
gd->cmd_sort->cmd[i].n_register, &response_size);
@@ -154,7 +152,6 @@ int modbus_value_handle(void *ctx, uint8_t slave_id, uint16_t n_byte,
uint16_t v1 = ((uint16_t *) dvalue.value.bytes)[0];
uint16_t v2 = ((uint16_t *) dvalue.value.bytes)[1];
uint32_t v = 0;
float * pf = (float *) &v;
switch ((*p_tag)->option.value32.endian) {
case NEU_DATATAG_ENDIAN_BB32:
@@ -175,7 +172,7 @@ int modbus_value_handle(void *ctx, uint8_t slave_id, uint16_t n_byte,
}
dvalue.type = NEU_TYPE_FLOAT;
dvalue.value.f32 = *pf;
dvalue.value.u32 = v;
break;
}
case NEU_TYPE_INT32:
+2 -3
View File
@@ -51,7 +51,6 @@ void handle_login(nng_aio *aio)
neu_json_login_resp_t login_resp = { 0 };
char * name = "admin";
char * password = "0000";
int ret = 0;
if (strcmp(req->name, name) == 0 &&
strcmp(req->pass, password) == 0) {
@@ -59,7 +58,7 @@ void handle_login(nng_aio *aio)
char *token = NULL;
char *result = NULL;
ret = neu_jwt_new(&token);
int ret = neu_jwt_new(&token);
if (ret != 0) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_NEED_TOKEN, {
http_response(aio, error_code.error, result_error);
@@ -125,7 +124,7 @@ void handle_get_plugin_schema(nng_aio *aio)
VALIDATE_JWT(aio);
const char *plugin_name = http_get_param(aio, "plugin_name", &len);
if (plugin_name == NULL || len <= 0) {
if (plugin_name == NULL || len == 0) {
http_bad_request(aio, "{\"error\": 1002}");
return;
}
+3 -4
View File
@@ -366,15 +366,14 @@ int neu_adapter_driver_add_group(neu_adapter_driver_t *driver, const char *name,
int neu_adapter_driver_del_group(neu_adapter_driver_t *driver, const char *name)
{
group_t *find = NULL;
int ret = NEU_ERR_GROUP_NOT_EXIST;
uint16_t tag_size = 0;
group_t *find = NULL;
int ret = NEU_ERR_GROUP_NOT_EXIST;
HASH_FIND_STR(driver->groups, name, find);
if (find != NULL) {
HASH_DEL(driver->groups, find);
tag_size = neu_group_tag_size(find->group);
uint16_t tag_size = neu_group_tag_size(find->group);
neu_adapter_del_timer((neu_adapter_t *) driver, find->report);
neu_event_del_timer(driver->driver_events, find->read);
if (find->grp.group_free != NULL) {
+2 -2
View File
@@ -222,10 +222,10 @@ bool neu_datatag_string_is_utf8(char *data, int len)
int neu_datatag_string_htol(char *str, int len)
{
char t = 0;
for (int i = 0; i < len; i += 2) {
t = str[i];
char t = str[i];
str[i] = str[i + 1];
str[i + 1] = t;
}
+3
View File
@@ -64,6 +64,9 @@ int neu_manager_add_node(neu_manager_t *manager, const char *node_name,
ret = neu_plugin_manager_create_instance(manager->plugin_manager,
plugin_name, &instance);
if (ret != 0) {
return NEU_ERR_LIBRARY_FAILED_TO_OPEN;
}
adapter_info.handle = instance.handle;
adapter_info.module = instance.module;
-8
View File
@@ -37,14 +37,6 @@ typedef struct sub_elem {
UT_hash_handle hh;
} sub_elem_t;
typedef struct app_elem {
char name[NEU_NODE_NAME_LEN];
UT_array *groups;
UT_hash_handle hh;
} app_elem_t;
static const UT_icd app_sub_icd = { sizeof(neu_app_subscribe_t), NULL, NULL,
NULL };
+3 -3
View File
@@ -58,7 +58,7 @@ int neu_json_decode_add_tags_req(char *buf, neu_json_add_tags_req_t **result)
req->group = req_elems[1].v.val_str;
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
if (req->n_tag < 0) {
if (req->n_tag <= 0) {
goto decode_fail;
}
@@ -193,7 +193,7 @@ int neu_json_decode_del_tags_req(char *buf, neu_json_del_tags_req_t **result)
req->group = req_elems[1].v.val_str;
req->n_tags = neu_json_decode_array_size_by_json(json_obj, "tags");
if (req->n_tags < 0) {
if (req->n_tags <= 0) {
goto decode_fail;
}
@@ -328,7 +328,7 @@ int neu_json_decode_update_tags_req(char * buf,
req->group = req_elems[1].v.val_str;
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
if (req->n_tag < 0) {
if (req->n_tag <= 0) {
goto decode_fail;
}
+1 -1
View File
@@ -41,7 +41,7 @@ int neu_json_decode_datatag_req(char *buf, neu_json_datatag_req_t **result)
json_obj = neu_json_decode_new(buf);
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
if (req->n_tag < 0) {
if (req->n_tag <= 0) {
goto decode_fail;
}
+1 -1
View File
@@ -41,7 +41,7 @@ int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result)
json_obj = neu_json_decode_new(buf);
req->n_plugin = neu_json_decode_array_size_by_json(json_obj, "plugins");
if (req->n_plugin < 0) {
if (req->n_plugin <= 0) {
goto decode_fail;
}
+1 -1
View File
@@ -44,7 +44,7 @@ int neu_json_decode_subscriptions_req(char * buf,
req->n_subscription =
neu_json_decode_array_size_by_json(json_obj, "subscriptions");
if (req->n_subscription < 0) {
if (req->n_subscription <= 0) {
goto decode_fail;
}