From 70a2e6e624ae7785c0e5eeb8f5caecfc0ee157c8 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Tue, 10 Aug 2010 08:59:11 +0200 Subject: [PATCH] Test return code of receive_msg_req to have an explicit error path --- src/modbus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modbus.c b/src/modbus.c index d12e3df..4d9a2fc 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -1295,10 +1295,12 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, int i; rc = receive_msg_req(ctx, req, rsp); + if (rc == -1) { + return -1; + } offset = TAB_HEADER_LENGTH[ctx->type_com]; - /* If rc is negative, the loop is jumped ! */ for (i = 0; i < rc; i++) { /* shift reg hi_byte to temp OR with lo_byte */ data_dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | -- libgit2 0.21.4