From 92dca473b1a8735c08dcc3b6aefc4199f507e763 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Mon, 28 Nov 2022 02:09:55 +0100 Subject: [PATCH] Convert a few int to unsigned int (#402) --- src/modbus.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/modbus.c b/src/modbus.c index b278440..4cf6083 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -353,7 +353,7 @@ int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) fd_set rset; struct timeval tv; struct timeval *p_tv; - int length_to_read; + unsigned int length_to_read; int msg_length = 0; _step_t step; #ifdef _WIN32 @@ -490,7 +490,7 @@ int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) } /* else switches straight to the next step */ case _STEP_META: length_to_read = compute_data_length_after_meta(ctx, msg, msg_type); - if ((msg_length + length_to_read) > (int) ctx->backend->max_adu_length) { + if ((msg_length + length_to_read) > ctx->backend->max_adu_length) { errno = EMBBADDATA; _error_print(ctx, "too many data"); return -1; @@ -554,7 +554,7 @@ static int check_confirmation(modbus_t *ctx, uint8_t *req, uint8_t *rsp, int rsp { int rc; int rsp_length_computed; - const int offset = ctx->backend->header_length; + const unsigned int offset = ctx->backend->header_length; const int function = rsp[offset]; if (ctx->backend->pre_check_confirmation) { @@ -572,7 +572,7 @@ static int check_confirmation(modbus_t *ctx, uint8_t *req, uint8_t *rsp, int rsp /* Exception code */ if (function >= 0x80) { - if (rsp_length == (offset + 2 + (int) ctx->backend->checksum_length) && + if (rsp_length == (int) (offset + 2 + ctx->backend->checksum_length) && req[offset] == (rsp[offset] - 0x80)) { /* Valid exception code received */ @@ -779,7 +779,7 @@ int modbus_reply(modbus_t *ctx, int req_length, modbus_mapping_t *mb_mapping) { - int offset; + unsigned int offset; int slave; int function; uint16_t address; @@ -1139,7 +1139,7 @@ int modbus_reply(modbus_t *ctx, int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, unsigned int exception_code) { - int offset; + unsigned int offset; int slave; int function; uint8_t rsp[MAX_MESSAGE_LENGTH]; @@ -1184,10 +1184,10 @@ static int read_io_status(modbus_t *ctx, int function, int addr, int nb, uint8_t rc = send_msg(ctx, req, req_length); if (rc > 0) { - int i, temp, bit; + int temp, bit; int pos = 0; - int offset; - int offset_end; + unsigned int offset; + unsigned int offset_end; rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION); if (rc == -1) @@ -1199,7 +1199,7 @@ static int read_io_status(modbus_t *ctx, int function, int addr, int nb, uint8_t offset = ctx->backend->header_length + 2; offset_end = offset + rc; - for (i = offset; i < offset_end; i++) { + for (unsigned int i = offset; i < offset_end; i++) { /* Shift reg hi_byte to temp */ temp = rsp[i]; @@ -1295,7 +1295,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_ rc = send_msg(ctx, req, req_length); if (rc > 0) { - int offset; + unsigned int offset; int i; rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION); @@ -1630,7 +1630,7 @@ int modbus_write_and_read_registers(modbus_t *ctx, rc = send_msg(ctx, req, req_length); if (rc > 0) { - int offset; + unsigned int offset; rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION); if (rc == -1) @@ -1672,7 +1672,7 @@ int modbus_report_slave_id(modbus_t *ctx, int max_dest, uint8_t *dest) rc = send_msg(ctx, req, req_length); if (rc > 0) { int i; - int offset; + unsigned int offset; uint8_t rsp[MAX_MESSAGE_LENGTH]; rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION); -- libgit2 0.21.4