Skip to content

Commit

Permalink
Merge pull request #3320 from BsAtHome/fix_printf-format-signed-unsigned
Browse files Browse the repository at this point in the history
Fix printf/scanf format signed/unsigned
  • Loading branch information
andypugh authored Feb 6, 2025
2 parents 21fe47f + 17fae0a commit 6f2c32a
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/emc/nml_intf/emc_nml.hh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class EMC_SET_DEBUG:public RCS_CMD_MSG {
// For internal NML/CMS use only.
void update(CMS * cms);

int debug;
unsigned debug;
};


Expand Down
2 changes: 1 addition & 1 deletion src/emc/nml_intf/emcglb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ char emc_nmlfile[LINELEN] = EMC2_DEFAULT_NMLFILE;
char rs274ngc_startup_code[LINELEN] =
DEFAULT_RS274NGC_STARTUP_CODE;

int emc_debug = 0; /* initially no debug messages */
unsigned emc_debug = 0; /* initially no debug messages */

double emc_task_cycle_time = DEFAULT_EMC_TASK_CYCLE_TIME;

Expand Down
2 changes: 1 addition & 1 deletion src/emc/nml_intf/emcglb.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" {
get these into Tk automatically */

// there's also an emc_Debug function in emc/usr_intf/emcsh.cc
extern int emc_debug;
extern unsigned emc_debug;

// EMC_DEBUG_* flag definitions moved to debugflags.h

Expand Down
4 changes: 2 additions & 2 deletions src/emc/task/emcsvr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ static int iniLoad(const char *filename)

// set flags if RCS_DEBUG in ini file
if ((inistring = inifile.Find("RCS_DEBUG", "EMC"))) {
static long int flags;
long unsigned int flags;
if (sscanf(*inistring, "%lx", &flags) < 1) {
perror("failed to parse [EMC] RCS_DEBUG");
}
// clear all flags
clear_rcs_print_flag(PRINT_EVERYTHING);
// set parsed flags
set_rcs_print_flag(flags);
set_rcs_print_flag((long)flags);
}
// output infinite RCS errors by default
max_rcs_errors_to_print = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/emc/task/emctaskmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void readahead_waiting(void)
int was_open = taskplanopen;
if (was_open) {
emcTaskPlanClose();
if (emc_debug & EMC_DEBUG_INTERP && was_open) {
if ((emc_debug & EMC_DEBUG_INTERP) && was_open) {
rcs_print
("emcTaskPlanClose() called at %s:%d\n",
__FILE__, __LINE__);
Expand Down Expand Up @@ -3146,14 +3146,14 @@ static int iniLoad(const char *filename)

// set flags if RCS_DEBUG in ini file
if ((inistring = inifile.Find("RCS_DEBUG", "EMC"))) {
static long int flags;
long unsigned int flags;
if (sscanf(*inistring, "%lx", &flags) < 1) {
perror("failed to parse [EMC] RCS_DEBUG");
}
// clear all flags
clear_rcs_print_flag(PRINT_EVERYTHING);
// set parsed flags
set_rcs_print_flag(flags);
set_rcs_print_flag((long)flags);
}
// output infinite RCS errors by default
max_rcs_errors_to_print = -1;
Expand Down
22 changes: 11 additions & 11 deletions src/emc/tooldata/tool_watch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ int main(int argc, char **argv) {
#else
fprintf(stderr,"tool_watch: TOOLTABLE:mmap\n");
#endif
fprintf(stderr,"%8ld EMC_STAT\n",sizeof(EMC_STAT));
fprintf(stderr,"%8ld EMC_IO_STAT\n",sizeof(EMC_IO_STAT));
fprintf(stderr,"%8ld EMC_TOOL_STAT\n",sizeof(EMC_TOOL_STAT));
fprintf(stderr,"%8ld EMC_COOLANT_STAT\n",sizeof(EMC_COOLANT_STAT));
fprintf(stderr,"%8ld EMC_AUX_STAT\n",sizeof(EMC_AUX_STAT));
fprintf(stderr,"%8ld EMC_TASK_STAT\n",sizeof(EMC_TASK_STAT));
fprintf(stderr,"%8ld EMC_MOTION_STAT\n",sizeof(EMC_MOTION_STAT));
fprintf(stderr,"%8ld EMC_TRAJ_STAT\n",sizeof(EMC_TRAJ_STAT));
fprintf(stderr,"%8ld EMC_JOINT_STAT\n",sizeof(EMC_JOINT_STAT));
fprintf(stderr,"%8ld EMC_AXIS_STAT\n",sizeof(EMC_AXIS_STAT));
fprintf(stderr,"%8ld EMC_SPINDLE_STAT\n",sizeof(EMC_SPINDLE_STAT));
fprintf(stderr,"%8zu EMC_STAT\n",sizeof(EMC_STAT));
fprintf(stderr,"%8zu EMC_IO_STAT\n",sizeof(EMC_IO_STAT));
fprintf(stderr,"%8zu EMC_TOOL_STAT\n",sizeof(EMC_TOOL_STAT));
fprintf(stderr,"%8zu EMC_COOLANT_STAT\n",sizeof(EMC_COOLANT_STAT));
fprintf(stderr,"%8zu EMC_AUX_STAT\n",sizeof(EMC_AUX_STAT));
fprintf(stderr,"%8zu EMC_TASK_STAT\n",sizeof(EMC_TASK_STAT));
fprintf(stderr,"%8zu EMC_MOTION_STAT\n",sizeof(EMC_MOTION_STAT));
fprintf(stderr,"%8zu EMC_TRAJ_STAT\n",sizeof(EMC_TRAJ_STAT));
fprintf(stderr,"%8zu EMC_JOINT_STAT\n",sizeof(EMC_JOINT_STAT));
fprintf(stderr,"%8zu EMC_AXIS_STAT\n",sizeof(EMC_AXIS_STAT));
fprintf(stderr,"%8zu EMC_SPINDLE_STAT\n",sizeof(EMC_SPINDLE_STAT));
fprintf(stderr,"\n");

header();hdr_ct=1;
Expand Down
4 changes: 2 additions & 2 deletions src/emc/usr_intf/halui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1430,14 +1430,14 @@ static int iniLoad(const char *filename)

// set flags if RCS_DEBUG in ini file
if ((inistring = inifile.Find("RCS_DEBUG", "EMC"))) {
static long int flags;
long unsigned int flags;
if (sscanf(*inistring, "%lx", &flags) < 1) {
perror("failed to parse [EMC] RCS_DEBUG");
}
// clear all flags
clear_rcs_print_flag(PRINT_EVERYTHING);
// set parsed flags
set_rcs_print_flag(flags);
set_rcs_print_flag((long)flags);
}
// output infinite RCS errors by default
max_rcs_errors_to_print = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/emc/usr_intf/shcom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1302,14 +1302,14 @@ int iniLoad(const char *filename)

// set flags if RCS_DEBUG in ini file
if ((inistring = inifile.Find("RCS_DEBUG", "EMC"))) {
static long int flags;
long unsigned int flags;
if (sscanf(*inistring, "%lx", &flags) < 1) {
perror("failed to parse [EMC] RCS_DEBUG");
}
// clear all flags
clear_rcs_print_flag(PRINT_EVERYTHING);
// set parsed flags
set_rcs_print_flag(flags);
set_rcs_print_flag((long)flags);
}
// output infinite RCS errors by default
max_rcs_errors_to_print = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/classicladder/config_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void GetIOSettings( char ForInputs )
case 2:
text = (char *)gtk_entry_get_text((GtkEntry *)*IOParamEntry);
if ( DeviceTypeValue==DEVICE_TYPE_DIRECT_ACCESS )
sscanf( text, "%X", &pConf->SubDevOrAdr );
sscanf( text, "%X", (unsigned *)&pConf->SubDevOrAdr );
else
pConf->SubDevOrAdr = atoi( text );
break;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/panelui.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int main(int argc, char **argv)
last_sample = this_sample;
}
if ( tag ) {
printf ( "%d ", this_sample-1 );
printf ( "%u ", this_sample-1 );
}
/* get raw value, mask keyup and keydown codes */
/* compute row and column */
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/sampler_usr.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int main(int argc, char **argv)
last_sample = this_sample;
}
if ( tag ) {
printf ( "%d ", this_sample-1 );
printf ( "%u ", this_sample-1 );
}
for ( n = 0 ; n < num_pins; n++ ) {
switch ( hal_stream_element_type(&stream, n) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/hal/user_comps/mb2hal/mb2hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void *link_loop_and_logic(void *thrd_link_num)
}
else if (ret != retOK) { //transaction failure but link OK
(**this_mb_tx->num_errors)++;
ERR(this_mb_tx->cfg_debug, "mb_tx_num[%d] mb_links[%d] thread[%d] fd[%d] transaction failure, num_errors[%d]",
ERR(this_mb_tx->cfg_debug, "mb_tx_num[%d] mb_links[%d] thread[%d] fd[%d] transaction failure, num_errors[%u]",
this_mb_tx_num, this_mb_tx->mb_link_num, this_mb_link_num, modbus_get_socket(this_mb_link->modbus), **this_mb_tx->num_errors);
// Clear any unread data. Otherwise the link might get out of sync
modbus_flush(this_mb_link->modbus);
Expand Down
2 changes: 1 addition & 1 deletion src/hal/user_comps/pi500_vfd/pi500_vfd.comp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool pi500_getStatus(modbus_t* ctx, pi500_status* status)
void print_modbus_error(struct __comp_state *__comp_inst, const char* msg)
{
fprintf(stderr,
"Error: pi500_vfd slave(%d): %s - Modbus error (%d) - %s\n",
"Error: pi500_vfd slave(%u): %s - Modbus error (%d) - %s\n",
mbslaveaddr,
msg,
errno,
Expand Down
2 changes: 1 addition & 1 deletion src/hal/user_comps/wj200_vfd/wj200_vfd.comp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool wj200_getStatus(modbus_t* ctx, wj200_status* status)
void print_modbus_error(struct __comp_state *__comp_inst, const char* msg)
{
fprintf(stderr,
"Error: wj200_vfd slave(%d): %s - Modbus error (%d) - %s\n",
"Error: wj200_vfd slave(%u): %s - Modbus error (%d) - %s\n",
mbslaveaddr,
msg,
errno,
Expand Down
2 changes: 1 addition & 1 deletion src/hal/utils/halcmd_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,7 @@ static const char *data_value2(int type, void *valptr)
value_str = buf;
break;
case HAL_U32:
snprintf(buf, 14, "%ld", (unsigned long)*((hal_u32_t *) valptr));
snprintf(buf, 14, "%lu", (unsigned long)*((hal_u32_t *) valptr));
value_str = buf;
break;
case HAL_S64:
Expand Down
4 changes: 2 additions & 2 deletions src/hal/utils/halrmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ static void getThreadInfo(char *pattern, connectionRecType *context)
}
}

snprintf(context->outBuf, sizeof(context->outBuf), "THREAD %s %11d %s %d %d",
snprintf(context->outBuf, sizeof(context->outBuf), "THREAD %s %11u %s %u %u",
tptr->name,
(unsigned int)tptr->period,
(tptr->uses_fp ? "YES" : "NO "),
Expand Down Expand Up @@ -2072,7 +2072,7 @@ static char *data_value2(int type, void *valptr)
value_str = buf;
break;
case HAL_U32:
snprintf(buf, 14, "%ld", (unsigned long)*((hal_u32_t *) valptr));
snprintf(buf, 14, "%lu", (unsigned long)*((hal_u32_t *) valptr));
value_str = buf;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/hal/utils/upci.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ int upci_scan_bus(void)
devices[num_devs++] = dev;
n = sscanf(lineptr,
"%hx %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
&busdevfunc, &vendordev, &(dev->p.irq),
&busdevfunc, &vendordev, (unsigned *)&(dev->p.irq),
&dev->p.base_addr[0], &dev->p.base_addr[1], &dev->p.base_addr[2],
&dev->p.base_addr[3], &dev->p.base_addr[4], &dev->p.base_addr[5],
&dev->p.rom_base_addr,
Expand Down
4 changes: 2 additions & 2 deletions src/libnml/cms/cms_aup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ CMS_STATUS CMS_ASCII_UPDATER::update(unsigned int &x)
x);
}
end_current_string[7] = 0;
sprintf(end_current_string, "%-6d", x);
sprintf(end_current_string, "%-6u", x);
if (end_current_string[7] != 0 && warning_count < warning_count_max) {
warning_count++;
rcs_print_error
Expand Down Expand Up @@ -631,7 +631,7 @@ CMS_STATUS CMS_ASCII_UPDATER::update(unsigned long int &x)

if (encoding) {
end_current_string[15] = 0;
sprintf(end_current_string, "%-14ld", x);
sprintf(end_current_string, "%-14lu", x);
if (end_current_string[15] != 0 && warning_count < warning_count_max) {
warning_count++;
rcs_print_error
Expand Down
4 changes: 2 additions & 2 deletions src/libnml/cms/cms_dup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ CMS_STATUS CMS_DISPLAY_ASCII_UPDATER::update(unsigned int &x)
("CMS_DISPLAY_ASCII_UPDATER: unsigned int %d is too large. (Use type long.)\n",
x);
}
snprintf(end_current_string, max_length_current_string-(end_current_string - begin_current_string), "%6d,", x);
snprintf(end_current_string, max_length_current_string-(end_current_string - begin_current_string), "%6u,", x);
} else {
if (0 == end_current_string[0]) {
x = 0;
Expand Down Expand Up @@ -635,7 +635,7 @@ CMS_STATUS CMS_DISPLAY_ASCII_UPDATER::update(unsigned long int &x)
}

if (encoding) {
snprintf(end_current_string, max_length_current_string-(end_current_string - begin_current_string), "%ld,", x);
snprintf(end_current_string, max_length_current_string-(end_current_string - begin_current_string), "%lu,", x);

} else {
if (0 == end_current_string[0]) {
Expand Down
4 changes: 2 additions & 2 deletions src/rtapi/rtai_ulapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void rtapi_printall(void)
printf(" key = %d\n", shmems[n].key);
printf(" rtusers = %d\n", shmems[n].rtusers);
printf(" ulusers = %d\n", shmems[n].ulusers);
printf(" size = %ld\n", shmems[n].size);
printf(" size = %lu\n", shmems[n].size);
printf(" bitmap = ");
for (m = 0; m <= RTAPI_MAX_MODULES; m++) {
if (test_bit(m, shmems[n].bitmap)) {
Expand Down Expand Up @@ -386,7 +386,7 @@ void rtapi_printall(void)
printf(" key = %d\n", fifos[n].key);
printf(" reader = %d\n", fifos[n].reader);
printf(" writer = %d\n", fifos[n].writer);
printf(" size = %ld\n", fifos[n].size);
printf(" size = %lu\n", fifos[n].size);
}
}
for (n = 0; n <= RTAPI_MAX_IRQS; n++) {
Expand Down
2 changes: 1 addition & 1 deletion src/rtapi/uspace_rtapi_parport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void map_parports() {
}
struct portinfo pi;
pi.port_id = i;
if(fscanf(f, "%hd %hd", &pi.base, &pi.base_hi) != 2) {
if(fscanf(f, "%hu %hu", &pi.base, &pi.base_hi) != 2) {
rtapi_print_msg(RTAPI_MSG_ERR, "Failed to parse base-addr for port #%d\n", i);
fclose(f);
continue;
Expand Down

0 comments on commit 6f2c32a

Please sign in to comment.