verify that the length of modbus bytes point is even

This commit is contained in:
hxy7yx
2023-10-11 13:48:18 +08:00
parent c2471d7869
commit e7bf3c74ca
2 changed files with 6 additions and 2 deletions
+2 -1
View File
@@ -168,7 +168,8 @@ int modbus_tag_to_point(const neu_datatag_t *tag, modbus_point_t *point)
point->area == MODBUS_AREA_INPUT) {
ret = NEU_ERR_TAG_TYPE_NOT_SUPPORT;
} else {
if (point->option.bytes.length > 128) {
if (point->option.bytes.length > 128 ||
point->option.bytes.length % 2 == 1) {
return NEU_ERR_TAG_ADDRESS_FORMAT_INVALID;
}
point->n_register =
+4 -1
View File
@@ -152,7 +152,10 @@ int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
{
modbus_point_t *p = calloc(1, sizeof(modbus_point_t));
int ret = modbus_tag_to_point(tag, p);
assert(ret == 0);
if (ret != NEU_ERR_SUCCESS) {
plog_error(plugin, "invalid tag: %s, address: %s", tag->name,
tag->address);
}
utarray_push_back(gd->tags, &p);
}