Explorar o código

Test return code of receive_msg_req to have an explicit error path

Stéphane Raimbault %!s(int64=15) %!d(string=hai) anos
pai
achega
70a2e6e624
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      src/modbus.c

+ 3 - 1
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) |