Commit 70a2e6e624ae7785c0e5eeb8f5caecfc0ee157c8
1 parent
bf763c96
Test return code of receive_msg_req to have an explicit error path
Showing
1 changed file
with
3 additions
and
1 deletions
src/modbus.c
| @@ -1295,10 +1295,12 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | @@ -1295,10 +1295,12 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | ||
| 1295 | int i; | 1295 | int i; |
| 1296 | 1296 | ||
| 1297 | rc = receive_msg_req(ctx, req, rsp); | 1297 | rc = receive_msg_req(ctx, req, rsp); |
| 1298 | + if (rc == -1) { | ||
| 1299 | + return -1; | ||
| 1300 | + } | ||
| 1298 | 1301 | ||
| 1299 | offset = TAB_HEADER_LENGTH[ctx->type_com]; | 1302 | offset = TAB_HEADER_LENGTH[ctx->type_com]; |
| 1300 | 1303 | ||
| 1301 | - /* If rc is negative, the loop is jumped ! */ | ||
| 1302 | for (i = 0; i < rc; i++) { | 1304 | for (i = 0; i < rc; i++) { |
| 1303 | /* shift reg hi_byte to temp OR with lo_byte */ | 1305 | /* shift reg hi_byte to temp OR with lo_byte */ |
| 1304 | data_dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | | 1306 | data_dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | |