Skip to content

Commit 92dca47

Browse files
committed
Convert a few int to unsigned int (#402)
1 parent 96c06aa commit 92dca47

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/modbus.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type)
353353
fd_set rset;
354354
struct timeval tv;
355355
struct timeval *p_tv;
356-
int length_to_read;
356+
unsigned int length_to_read;
357357
int msg_length = 0;
358358
_step_t step;
359359
#ifdef _WIN32
@@ -490,7 +490,7 @@ int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type)
490490
} /* else switches straight to the next step */
491491
case _STEP_META:
492492
length_to_read = compute_data_length_after_meta(ctx, msg, msg_type);
493-
if ((msg_length + length_to_read) > (int) ctx->backend->max_adu_length) {
493+
if ((msg_length + length_to_read) > ctx->backend->max_adu_length) {
494494
errno = EMBBADDATA;
495495
_error_print(ctx, "too many data");
496496
return -1;
@@ -554,7 +554,7 @@ static int check_confirmation(modbus_t *ctx, uint8_t *req, uint8_t *rsp, int rsp
554554
{
555555
int rc;
556556
int rsp_length_computed;
557-
const int offset = ctx->backend->header_length;
557+
const unsigned int offset = ctx->backend->header_length;
558558
const int function = rsp[offset];
559559

560560
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
572572

573573
/* Exception code */
574574
if (function >= 0x80) {
575-
if (rsp_length == (offset + 2 + (int) ctx->backend->checksum_length) &&
575+
if (rsp_length == (int) (offset + 2 + ctx->backend->checksum_length) &&
576576
req[offset] == (rsp[offset] - 0x80)) {
577577
/* Valid exception code received */
578578

@@ -779,7 +779,7 @@ int modbus_reply(modbus_t *ctx,
779779
int req_length,
780780
modbus_mapping_t *mb_mapping)
781781
{
782-
int offset;
782+
unsigned int offset;
783783
int slave;
784784
int function;
785785
uint16_t address;
@@ -1139,7 +1139,7 @@ int modbus_reply(modbus_t *ctx,
11391139

11401140
int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, unsigned int exception_code)
11411141
{
1142-
int offset;
1142+
unsigned int offset;
11431143
int slave;
11441144
int function;
11451145
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
11841184

11851185
rc = send_msg(ctx, req, req_length);
11861186
if (rc > 0) {
1187-
int i, temp, bit;
1187+
int temp, bit;
11881188
int pos = 0;
1189-
int offset;
1190-
int offset_end;
1189+
unsigned int offset;
1190+
unsigned int offset_end;
11911191

11921192
rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION);
11931193
if (rc == -1)
@@ -1199,7 +1199,7 @@ static int read_io_status(modbus_t *ctx, int function, int addr, int nb, uint8_t
11991199

12001200
offset = ctx->backend->header_length + 2;
12011201
offset_end = offset + rc;
1202-
for (i = offset; i < offset_end; i++) {
1202+
for (unsigned int i = offset; i < offset_end; i++) {
12031203
/* Shift reg hi_byte to temp */
12041204
temp = rsp[i];
12051205

@@ -1295,7 +1295,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_
12951295

12961296
rc = send_msg(ctx, req, req_length);
12971297
if (rc > 0) {
1298-
int offset;
1298+
unsigned int offset;
12991299
int i;
13001300

13011301
rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION);
@@ -1630,7 +1630,7 @@ int modbus_write_and_read_registers(modbus_t *ctx,
16301630

16311631
rc = send_msg(ctx, req, req_length);
16321632
if (rc > 0) {
1633-
int offset;
1633+
unsigned int offset;
16341634

16351635
rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION);
16361636
if (rc == -1)
@@ -1672,7 +1672,7 @@ int modbus_report_slave_id(modbus_t *ctx, int max_dest, uint8_t *dest)
16721672
rc = send_msg(ctx, req, req_length);
16731673
if (rc > 0) {
16741674
int i;
1675-
int offset;
1675+
unsigned int offset;
16761676
uint8_t rsp[MAX_MESSAGE_LENGTH];
16771677

16781678
rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION);

0 commit comments

Comments
 (0)