From 3335fd0e5526596d3f40947836c202d2f96385e9 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Sat, 11 Jan 2025 16:44:31 +0100 Subject: [PATCH] Fix signed/unsigned comparison mismatches. --- src/emc/usr_intf/axis/extensions/togl.c | 2 +- src/emc/usr_intf/sockets.c | 16 ++++++++-------- src/hal/classicladder/socket_modbus_master.c | 4 ++-- src/hal/classicladder/socket_server.c | 4 ++-- src/hal/hal.h | 4 ++-- src/hal/hal_lib.c | 10 +++++----- src/hal/hal_priv.h | 8 ++++---- src/hal/user_comps/gs2_vfd.c | 3 ++- src/hal/user_comps/huanyang-vfd/hy_vfd.c | 3 ++- src/hal/user_comps/hy_gt_vfd.c | 3 ++- src/hal/user_comps/mb2hal/mb2hal_init.c | 2 +- src/hal/user_comps/sendkeys.c | 2 +- src/hal/user_comps/shuttle.c | 2 +- src/hal/user_comps/svd-ps_vfd.c | 3 ++- src/hal/utils/halcmd.c | 6 +++--- src/hal/utils/halcmd_completion.c | 4 ++-- src/hal/utils/meter.c | 4 ++-- src/hal/utils/scope.c | 6 +----- src/module_helper/module_helper.c | 2 +- src/rtapi/uspace_common.h | 4 ++-- 20 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/emc/usr_intf/axis/extensions/togl.c b/src/emc/usr_intf/axis/extensions/togl.c index 793963674cd..ddf68867f7e 100644 --- a/src/emc/usr_intf/axis/extensions/togl.c +++ b/src/emc/usr_intf/axis/extensions/togl.c @@ -154,7 +154,7 @@ static LRESULT (CALLBACK *tkWinChildProc)(HWND hwnd, UINT message, /* The constant DUMMY_WINDOW is used to signal window creation failure from the Togl_CreateWindow() */ -#define DUMMY_WINDOW -1 +#define DUMMY_WINDOW ((Window)-1) #define ALL_EVENTS_MASK \ (KeyPressMask | \ diff --git a/src/emc/usr_intf/sockets.c b/src/emc/usr_intf/sockets.c index 211cb821bff..aab9a027bb2 100644 --- a/src/emc/usr_intf/sockets.c +++ b/src/emc/usr_intf/sockets.c @@ -138,7 +138,7 @@ int sockPrintf(int fd, const char *format, .../*args*/ ) rcs_print_error("sock_printf: vsnprintf failed\n"); return -1; } - if (size > sizeof(buf)) { + if (size > (int)sizeof(buf)) { rcs_print_error("sock_printf: vsnprintf truncated message\n"); } return sockSendString(fd, buf); @@ -182,7 +182,7 @@ int sockRecvString(int fd, char *dest, size_t maxlen) recvBytes++; // stop at max. bytes allowed, at NUL or at LF - if (recvBytes == maxlen || *ptr == '\0' || *ptr == '\n') { + if (recvBytes == (int)maxlen || *ptr == '\0' || *ptr == '\n') { *ptr = '\0'; break; } @@ -193,7 +193,7 @@ int sockRecvString(int fd, char *dest, size_t maxlen) if (recvBytes == 1 && dest[0] == '\0') return 0; - if (recvBytes < maxlen - 1) + if (recvBytes < (int)maxlen - 1) dest[recvBytes] = '\0'; return recvBytes; @@ -202,7 +202,7 @@ int sockRecvString(int fd, char *dest, size_t maxlen) // Send/receive raw data int sockSend(int fd, const void *src, size_t size) { - int offset = 0; + size_t offset = 0; if (!src) return -1; @@ -210,9 +210,9 @@ int sockSend(int fd, const void *src, size_t size) // write isn't guaranteed to send the entire string at once, // so we have to sent it in a loop like this #ifndef WINSOCK2 - int sent = write(fd, ((const char *) src) + offset, size - offset); + ssize_t sent = write(fd, ((const char *) src) + offset, size - offset); #else - int sent = send(fd, ((const char *) src) + offset, size - offset, 0); + ssize_t sent = send(fd, ((const char *) src) + offset, size - offset, 0); #endif if (sent == -1) { if (errno != EAGAIN) { @@ -226,7 +226,7 @@ int sockSend(int fd, const void *src, size_t size) offset += sent; } // while - return offset; + return (int)offset; } int sockRecv(int fd, void *dest, size_t maxlen) @@ -317,7 +317,7 @@ int sockPrintfError(int fd, const char *format, .../*args*/ ) rcs_print_error("sock_printf_error: vsnprintf failed\n"); return -1; } - if (size >= sizeof(buf) - (sizeof(huh)-1)) { + if (size >= (int)(sizeof(buf) - (sizeof(huh)-1))) { rcs_print_error("sock_printf_error: vsnprintf truncated message\n"); } diff --git a/src/hal/classicladder/socket_modbus_master.c b/src/hal/classicladder/socket_modbus_master.c index 1eb86cce900..ca3b50f1375 100644 --- a/src/hal/classicladder/socket_modbus_master.c +++ b/src/hal/classicladder/socket_modbus_master.c @@ -60,8 +60,8 @@ HANDLE ThreadHandleClient = NULL; DWORD ThreadIdClient; #else -#define SOCK_FD unsigned int -#define SOCK_INVALID -1 +#define SOCK_FD int +#define SOCK_INVALID (-1) pthread_t thread_socket_client; #endif diff --git a/src/hal/classicladder/socket_server.c b/src/hal/classicladder/socket_server.c index 66343f8da8d..482e6e9f3da 100644 --- a/src/hal/classicladder/socket_server.c +++ b/src/hal/classicladder/socket_server.c @@ -56,8 +56,8 @@ HANDLE ThreadHandle = NULL; DWORD ThreadId; #else -#define SOCK_FD unsigned int -#define SOCK_INVALID -1 +#define SOCK_FD int +#define SOCK_INVALID (-1) pthread_t thread_socket_server; #endif diff --git a/src/hal/hal.h b/src/hal/hal.h index 96bd7c49203..b5549718f60 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -959,7 +959,7 @@ typedef struct { #define HAL_STREAM_MAX_PINS (21) /** create and attach a stream */ -extern int hal_stream_create(hal_stream_t *stream, int comp, int key, int depth, const char *typestring); +extern int hal_stream_create(hal_stream_t *stream, int comp, int key, unsigned depth, const char *typestring); /** detach and destroy an open stream */ extern void hal_stream_destroy(hal_stream_t *stream); @@ -976,7 +976,7 @@ extern hal_type_t hal_stream_element_type(hal_stream_t *stream, int idx); extern int hal_stream_read(hal_stream_t *stream, union hal_stream_data *buf, unsigned *sampleno); extern bool hal_stream_readable(hal_stream_t *stream); extern int hal_stream_depth(hal_stream_t *stream); -extern int hal_stream_maxdepth(hal_stream_t *stream); +extern unsigned hal_stream_maxdepth(hal_stream_t *stream); extern int hal_stream_num_underruns(hal_stream_t *stream); extern int hal_stream_num_overruns(hal_stream_t *stream); #ifdef ULAPI diff --git a/src/hal/hal_lib.c b/src/hal/hal_lib.c index 739f952cdec..33a9815e6ce 100644 --- a/src/hal/hal_lib.c +++ b/src/hal/hal_lib.c @@ -4111,7 +4111,7 @@ int halpr_parse_types(hal_type_t type[HAL_STREAM_MAX_PINS], const char *cfg) return n; } -int hal_stream_create(hal_stream_t *stream, int comp, int key, int depth, const char *typestring) +int hal_stream_create(hal_stream_t *stream, int comp, int key, unsigned depth, const char *typestring) { int result = 0; hal_type_t type[HAL_STREAM_MAX_PINS]; @@ -4144,13 +4144,13 @@ extern void hal_stream_destroy(hal_stream_t *stream) hal_stream_detach(stream); } -static int hal_stream_advance(hal_stream_t *stream, int n) { +static unsigned hal_stream_advance(hal_stream_t *stream, unsigned n) { n = n + 1; if(n >= stream->fifo->depth) n = 0; return n; } -static int hal_stream_newin(hal_stream_t *stream) { +static unsigned hal_stream_newin(hal_stream_t *stream) { return hal_stream_advance(stream, stream->fifo->in); } @@ -4170,7 +4170,7 @@ int hal_stream_depth(hal_stream_t *stream) { return result; } -int hal_stream_maxdepth(hal_stream_t *stream) { +unsigned hal_stream_maxdepth(hal_stream_t *stream) { return stream->fifo->depth; } @@ -4280,7 +4280,7 @@ int hal_stream_attach(hal_stream_t *stream, int comp_id, int key, const char *ty } } /* now use data in fifo structure to calculate proper shmem size */ - int depth = fifo->depth; + unsigned depth = fifo->depth; int pin_count = fifo->num_pins; size_t size = sizeof(struct hal_stream_shm) + sizeof(union hal_stream_data) * depth * (1+pin_count); /* close shmem, re-open with proper size */ diff --git a/src/hal/hal_priv.h b/src/hal/hal_priv.h index faa404979d5..3e94752a85d 100644 --- a/src/hal/hal_priv.h +++ b/src/hal/hal_priv.h @@ -493,11 +493,11 @@ extern int hal_port_alloc(unsigned size, hal_port_t *port); #define HAL_STREAM_MAGIC_NUM 0x4649464F struct hal_stream_shm { - unsigned int magic; - volatile unsigned int in; - volatile unsigned int out; + unsigned magic; + volatile unsigned in; + volatile unsigned out; unsigned this_sample; - int depth; + unsigned depth; int num_pins; unsigned long num_overruns, num_underruns; hal_type_t type[HAL_STREAM_MAX_PINS]; diff --git a/src/hal/user_comps/gs2_vfd.c b/src/hal/user_comps/gs2_vfd.c index 9488e3ad99a..e1ac076f84d 100644 --- a/src/hal/user_comps/gs2_vfd.c +++ b/src/hal/user_comps/gs2_vfd.c @@ -168,7 +168,8 @@ static void quit(int sig) { static int comm_delay = 0; // JET delay counter for at-speed int match_string(char *string, char **matches) { - int len, which, match; + size_t len; + int which, match; which=0; match=-1; if ((matches==NULL) || (string==NULL)) return -1; diff --git a/src/hal/user_comps/huanyang-vfd/hy_vfd.c b/src/hal/user_comps/huanyang-vfd/hy_vfd.c index 8075d368a9e..9bfe12cf5b3 100644 --- a/src/hal/user_comps/huanyang-vfd/hy_vfd.c +++ b/src/hal/user_comps/huanyang-vfd/hy_vfd.c @@ -179,7 +179,8 @@ static char *ratestrings[] = {"110", "300", "600", "1200", "2400", "4800", "9600 static char *stopstrings[] = {"1", "2", NULL}; int match_string(char *string, char **matches) { - int len, which, match; + size_t len; + int which, match; which=0; match=-1; if ((matches==NULL) || (string==NULL)) return -1; diff --git a/src/hal/user_comps/hy_gt_vfd.c b/src/hal/user_comps/hy_gt_vfd.c index d36d167752c..b8cc2f637ef 100644 --- a/src/hal/user_comps/hy_gt_vfd.c +++ b/src/hal/user_comps/hy_gt_vfd.c @@ -122,7 +122,8 @@ static void quit(int sig) { int match_string(char *string, char **matches) { - int len, which, match; + size_t len; + int which, match; which=0; match=-1; if ((matches==NULL) || (string==NULL)) return -1; diff --git a/src/hal/user_comps/mb2hal/mb2hal_init.c b/src/hal/user_comps/mb2hal/mb2hal_init.c index 9e005aa66a7..76a6abd89ae 100644 --- a/src/hal/user_comps/mb2hal/mb2hal_init.c +++ b/src/hal/user_comps/mb2hal/mb2hal_init.c @@ -354,7 +354,7 @@ retCode parse_transaction_section(const int mb_tx_num) break; } } - int max = gbl.version<1001?mbtx_01_READ_COILS:mbtxMAX; + mb_tx_fnct max = gbl.version<1001?mbtx_01_READ_COILS:mbtxMAX; if (this_mb_tx->mb_tx_fnct <= mbtxERR || this_mb_tx->mb_tx_fnct >= max) { ERR(gbl.init_dbg, "[%s] [%s] [%s] out of range", section, tag, tmpstr); return retERR; diff --git a/src/hal/user_comps/sendkeys.c b/src/hal/user_comps/sendkeys.c index 63d18fb1ca2..32ac7b29e2e 100644 --- a/src/hal/user_comps/sendkeys.c +++ b/src/hal/user_comps/sendkeys.c @@ -271,7 +271,7 @@ int main(int argc, char* argv[]) { } if (*hal->keycode != param->oldcode) { /* Key press, report the event, send key release, and report again*/ - if ((*hal->keycode & 0x3F) > param->num_events) continue; + if ((int)(*hal->keycode & 0x3F) > param->num_events) continue; if (hal->event[*hal->keycode & 0x3F] == 0) continue; if ((*hal->keycode & 0xC0) == 0xC0){ // keydown emit(param->fd, EV_KEY, hal->event[*hal->keycode & 0x3F], 1); diff --git a/src/hal/user_comps/shuttle.c b/src/hal/user_comps/shuttle.c index 7e52bcda827..0b85ed1b8fc 100644 --- a/src/hal/user_comps/shuttle.c +++ b/src/hal/user_comps/shuttle.c @@ -217,7 +217,7 @@ struct shuttle *check_for_shuttle(char *dev_filename) { goto fail1; } - for (int i = 0; i < sizeof(contour_dev)/sizeof(contour_dev_t); i ++) { + for (unsigned i = 0; i < sizeof(contour_dev)/sizeof(contour_dev_t); i ++) { if (devinfo.vendor != contour_dev[i].vendor_id) { continue; } diff --git a/src/hal/user_comps/svd-ps_vfd.c b/src/hal/user_comps/svd-ps_vfd.c index 6280f0e5610..846c0d989f2 100644 --- a/src/hal/user_comps/svd-ps_vfd.c +++ b/src/hal/user_comps/svd-ps_vfd.c @@ -114,7 +114,8 @@ static void quit(int sig) { int match_string(char *string, char **matches) { - int len, which, match; + size_t len; + int which, match; which=0; match=-1; if ((matches==NULL) || (string==NULL)) return -1; diff --git a/src/hal/utils/halcmd.c b/src/hal/utils/halcmd.c index 1973a394b08..7a2db36238f 100644 --- a/src/hal/utils/halcmd.c +++ b/src/hal/utils/halcmd.c @@ -748,7 +748,7 @@ static int replace_vars(char *source_str, char *dest_str, int max_chars, char ** if (*sp=='(') { /* look for a parenthesized var */ varP=++sp; next_delim=strcspn(varP, ")"); - if (next_delim >= strlen(varP)) /* error - no matching parens */ + if (next_delim >= (int)strlen(varP)) /* error - no matching parens */ return -1; sp++; } else next_delim = strspn(varP, words); @@ -773,7 +773,7 @@ static int replace_vars(char *source_str, char *dest_str, int max_chars, char ** case '[': secP = sp; next_delim = strcspn(secP, "]"); - if (next_delim >= strlen(secP)) /* error - no matching square bracket */ + if (next_delim >= (int)strlen(secP)) /* error - no matching square bracket */ return -3; if (next_delim > 127) /* section name too long */ return -7; @@ -784,7 +784,7 @@ static int replace_vars(char *source_str, char *dest_str, int max_chars, char ** if (*sp=='(') { /* look for a parenthesized var */ varP=++sp; next_delim=strcspn(varP, ")"); - if (next_delim > strlen(varP)) /* error - no matching parens */ + if (next_delim > (int)strlen(varP)) /* error - no matching parens */ return -1; sp++; } else next_delim = strspn(varP, words); diff --git a/src/hal/utils/halcmd_completion.c b/src/hal/utils/halcmd_completion.c index ede53a9e69a..d834af6e846 100644 --- a/src/hal/utils/halcmd_completion.c +++ b/src/hal/utils/halcmd_completion.c @@ -136,7 +136,7 @@ static int writer_match(hal_pin_dir_t dir, int writers) { static void check_match_type_pin(const char *name) { int next = hal_data->pin_list_ptr; - int sz = strcspn(name, " \t"); + size_t sz = strcspn(name, " \t"); while(next) { hal_pin_t *pin = SHMPTR(next); @@ -151,7 +151,7 @@ static void check_match_type_pin(const char *name) { static void check_match_type_signal(const char *name) { int next = hal_data->sig_list_ptr; - int sz = strcspn(name, " \t"); + size_t sz = strcspn(name, " \t"); while(next) { hal_sig_t *sig = SHMPTR(next); diff --git a/src/hal/utils/meter.c b/src/hal/utils/meter.c index 56ded9a8c0c..264ac58ab69 100644 --- a/src/hal/utils/meter.c +++ b/src/hal/utils/meter.c @@ -177,10 +177,10 @@ int main(int argc, gchar * argv[]) n++; if ( argc > n ){ rtapi_strxcpy(buf,argv[n]); - for (i=0; i< strlen(argv[n]); i++) { + for (i=0; i< (int)strlen(argv[n]); i++) { if (isdigit(buf[i]) == 0) { break; } } - if (strlen(argv[n]) == i){ + if ((int)strlen(argv[n]) == i){ width = atoi(argv[n]); n++; } diff --git a/src/hal/utils/scope.c b/src/hal/utils/scope.c index 1e2509d1536..ad7256177ca 100644 --- a/src/hal/utils/scope.c +++ b/src/hal/utils/scope.c @@ -413,14 +413,10 @@ void capture_complete(void) static void init_usr_control_struct(void *shmem) { - char *cp; int n, skip; /* first clear entire user struct to all zeros */ - cp = (char *) ctrl_usr; - for (n = 0; n < sizeof(scope_usr_control_t); n++) { - cp[n] = 0; - } + memset(ctrl_usr, 0, sizeof(scope_usr_control_t)); /* save pointer to shared control structure */ ctrl_shm = shmem; diff --git a/src/module_helper/module_helper.c b/src/module_helper/module_helper.c index 524eb95f571..f22c651ba50 100644 --- a/src/module_helper/module_helper.c +++ b/src/module_helper/module_helper.c @@ -208,7 +208,7 @@ int main(int argc, char **argv) { } res = snprintf(buf, sizeof(buf), "/usr/realtime-%s/modules", u.release); - if(res < 0 || res >= sizeof(buf)) + if(res < 0 || res >= (int)sizeof(buf)) { perror("snprintf"); return 1; diff --git a/src/rtapi/uspace_common.h b/src/rtapi/uspace_common.h index 88eb2c5dc47..9b076401aea 100644 --- a/src/rtapi/uspace_common.h +++ b/src/rtapi/uspace_common.h @@ -29,7 +29,7 @@ #include #include -static int msg_level = RTAPI_MSG_ERR; /* message printing level */ +static msg_level_t msg_level = RTAPI_MSG_ERR; /* message printing level */ #include /* IPC_* */ #include /* shmget() */ @@ -275,7 +275,7 @@ int rtapi_vsnprintf(char *buffer, unsigned long int size, const char *fmt, } int rtapi_set_msg_level(int level) { - msg_level = level; + msg_level = (msg_level_t)level; return 0; }