Skip to content

Commit

Permalink
Convert a few int to unsigned int (stephane#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane committed Nov 28, 2022
1 parent d5cede9 commit e0145da
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand All @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e0145da

Please sign in to comment.