Change snprintf to SNPRINTF in src

https://github.com/Hamlib/Hamlib/issues/857
pull/943/head
Mike Black W9MDB 2022-01-19 09:11:04 -06:00
rodzic 191ac98634
commit 09c9b01552
7 zmienionych plików z 38 dodań i 38 usunięć

Wyświetl plik

@ -343,19 +343,19 @@ int frontamp_get_conf2(AMP *amp, token_t token, char *val, int val_len)
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
snprintf(val, val_len, "%d", rs->ampport.write_delay); SNPRINTF(val, val_len, "%d", rs->ampport.write_delay);
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
snprintf(val, val_len, "%d", rs->ampport.post_write_delay); SNPRINTF(val, val_len, "%d", rs->ampport.post_write_delay);
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
snprintf(val, val_len, "%d", rs->ampport.timeout); SNPRINTF(val, val_len, "%d", rs->ampport.timeout);
break; break;
case TOK_RETRY: case TOK_RETRY:
snprintf(val, val_len, "%d", rs->ampport.retry); SNPRINTF(val, val_len, "%d", rs->ampport.retry);
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
@ -364,7 +364,7 @@ int frontamp_get_conf2(AMP *amp, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->ampport.parm.serial.rate); SNPRINTF(val, val_len, "%d", rs->ampport.parm.serial.rate);
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
@ -373,7 +373,7 @@ int frontamp_get_conf2(AMP *amp, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->ampport.parm.serial.data_bits); SNPRINTF(val, val_len, "%d", rs->ampport.parm.serial.data_bits);
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
@ -382,7 +382,7 @@ int frontamp_get_conf2(AMP *amp, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->ampport.parm.serial.stop_bits); SNPRINTF(val, val_len, "%d", rs->ampport.parm.serial.stop_bits);
break; break;
case TOK_PARITY: case TOK_PARITY:
@ -654,7 +654,7 @@ int HAMLIB_API amp_set_conf(AMP *amp, token_t token, const char *val)
{ {
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[12]; char tokenstr[12];
snprintf(tokenstr, sizeof(tokenstr), "%ld", token); SNPRINTF(tokenstr, sizeof(tokenstr), "%ld", token);
cfp = amp_confparam_lookup(amp, tokenstr); cfp = amp_confparam_lookup(amp, tokenstr);
if (!cfp) if (!cfp)

Wyświetl plik

@ -38,7 +38,7 @@ int gpio_open(hamlib_port_t *port, int output, int on_value)
port->parm.gpio.on_value = on_value; port->parm.gpio.on_value = on_value;
snprintf(pathname, HAMLIB_FILPATHLEN, "/sys/class/gpio/export"); SNPRINTF(pathname, HAMLIB_FILPATHLEN, "/sys/class/gpio/export");
fexp = fopen(pathname, "w"); fexp = fopen(pathname, "w");
if (!fexp) if (!fexp)
@ -54,7 +54,7 @@ int gpio_open(hamlib_port_t *port, int output, int on_value)
fprintf(fexp, "%s\n", port->pathname); fprintf(fexp, "%s\n", port->pathname);
fclose(fexp); fclose(fexp);
snprintf(pathname, SNPRINTF(pathname,
sizeof(pathname), sizeof(pathname),
"/sys/class/gpio/gpio%s/direction", "/sys/class/gpio/gpio%s/direction",
port->pathname); port->pathname);
@ -76,7 +76,7 @@ int gpio_open(hamlib_port_t *port, int output, int on_value)
fprintf(fdir, "%s\n", dir); fprintf(fdir, "%s\n", dir);
fclose(fdir); fclose(fdir);
snprintf(pathname, SNPRINTF(pathname,
sizeof(pathname), sizeof(pathname),
"/sys/class/gpio/gpio%s/value", "/sys/class/gpio/gpio%s/value",
port->pathname); port->pathname);

Wyświetl plik

@ -577,7 +577,7 @@ int HAMLIB_API rig_strrmodes(rmode_t modes, char *buf, int buflen)
if (modes == RIG_MODE_NONE) if (modes == RIG_MODE_NONE)
{ {
snprintf(buf, buflen, "NONE"); SNPRINTF(buf, buflen, "NONE");
return RIG_OK; return RIG_OK;
} }
@ -587,8 +587,8 @@ int HAMLIB_API rig_strrmodes(rmode_t modes, char *buf, int buflen)
{ {
char modebuf[16]; char modebuf[16];
if (strlen(buf) == 0) { snprintf(modebuf, sizeof(modebuf), "%s", mode_str[i].str); } if (strlen(buf) == 0) { SNPRINTF(modebuf, sizeof(modebuf), "%s", mode_str[i].str); }
else { snprintf(modebuf, sizeof(modebuf), " %s", mode_str[i].str); } else { SNPRINTF(modebuf, sizeof(modebuf), " %s", mode_str[i].str); }
strncat(buf, modebuf, buflen - strlen(buf) - 1); strncat(buf, modebuf, buflen - strlen(buf) - 1);
@ -2064,7 +2064,7 @@ int HAMLIB_API parse_hoststr(char *hoststr, int hoststr_len, char host[256], cha
if (sscanf(hoststr, ":%5[0-9]%1s", port, if (sscanf(hoststr, ":%5[0-9]%1s", port,
dummy) == 1) // just a port if you please dummy) == 1) // just a port if you please
{ {
snprintf(hoststr, hoststr_len, "%s:%s\n", "localhost", port); SNPRINTF(hoststr, hoststr_len, "%s:%s\n", "localhost", port);
rig_debug(RIG_DEBUG_VERBOSE, "%s: hoststr=%s\n", __func__, hoststr); rig_debug(RIG_DEBUG_VERBOSE, "%s: hoststr=%s\n", __func__, hoststr);
return RIG_OK; return RIG_OK;
} }
@ -2573,9 +2573,9 @@ char *date_strget(char *buf, int buflen, int localtime)
strftime(buf, buflen, "%Y-%m-%dT%H:%M:%S.", mytm); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%S.", mytm);
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
snprintf(tmpbuf, sizeof(tmpbuf), "%06ld", (long)tv.tv_usec); SNPRINTF(tmpbuf, sizeof(tmpbuf), "%06ld", (long)tv.tv_usec);
strcat(buf, tmpbuf); strcat(buf, tmpbuf);
snprintf(tmpbuf, sizeof(tmpbuf), "%s%04d", mytimezone >= 0 ? "-" : "+", SNPRINTF(tmpbuf, sizeof(tmpbuf), "%s%04d", mytimezone >= 0 ? "-" : "+",
((int)abs(mytimezone) / 3600) * 100); ((int)abs(mytimezone) / 3600) * 100);
strcat(buf, tmpbuf); strcat(buf, tmpbuf);
return buf; return buf;

Wyświetl plik

@ -237,7 +237,7 @@ int network_open(hamlib_port_t *rp, int default_port)
if (rp->pathname[0] == ':' && rp->pathname[1] != ':') if (rp->pathname[0] == ':' && rp->pathname[1] != ':')
{ {
snprintf(portstr, sizeof(portstr) - 1, "%s", rp->pathname + 1); SNPRINTF(portstr, sizeof(portstr) - 1, "%s", rp->pathname + 1);
} }
else else
{ {
@ -254,7 +254,7 @@ int network_open(hamlib_port_t *rp, int default_port)
if (strlen(portstr) == 0) if (strlen(portstr) == 0)
{ {
snprintf(portstr, sizeof(portstr), "%d", default_port); SNPRINTF(portstr, sizeof(portstr), "%d", default_port);
} }
} }
@ -318,7 +318,7 @@ int network_open(hamlib_port_t *rp, int default_port)
break; break;
} }
snprintf(msg, sizeof(msg), "connect to %s failed, (trying next interface)", SNPRINTF(msg, sizeof(msg), "connect to %s failed, (trying next interface)",
rp->pathname); rp->pathname);
handle_error(RIG_DEBUG_WARN, msg); handle_error(RIG_DEBUG_WARN, msg);

Wyświetl plik

@ -340,7 +340,7 @@ const char *HAMLIB_API rigerror(int errnum)
if (*p == '\n') { *p = 0; } if (*p == '\n') { *p = 0; }
snprintf(msg, sizeof(msg), "%.80s\n%.15000s%.15000s%.15000s", SNPRINTF(msg, sizeof(msg), "%.80s\n%.15000s%.15000s%.15000s",
rigerror_table[errnum], rigerror_table[errnum],
debugmsgsave3, debugmsgsave2, debugmsgsave); debugmsgsave3, debugmsgsave2, debugmsgsave);
return msg; return msg;
@ -6827,7 +6827,7 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
size_t len = strlen(cookie); size_t len = strlen(cookie);
// add on our random number to ensure uniqueness // add on our random number to ensure uniqueness
// The cookie should never be longer then HAMLIB_COOKIE_SIZE // The cookie should never be longer then HAMLIB_COOKIE_SIZE
snprintf(cookie + len, HAMLIB_COOKIE_SIZE - len, " %d\n", rand()); SNPRINTF(cookie + len, HAMLIB_COOKIE_SIZE - len, " %d\n", rand());
strcpy(cookie_save, cookie); strcpy(cookie_save, cookie);
time_last_used = time_curr; time_last_used = time_curr;
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s new cookie request granted\n", rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s new cookie request granted\n",

Wyświetl plik

@ -380,19 +380,19 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val, int val_len)
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
snprintf(val, val_len, "%d", rs->rotport.write_delay); SNPRINTF(val, val_len, "%d", rs->rotport.write_delay);
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
snprintf(val, val_len, "%d", rs->rotport.post_write_delay); SNPRINTF(val, val_len, "%d", rs->rotport.post_write_delay);
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
snprintf(val, val_len, "%d", rs->rotport.timeout); SNPRINTF(val, val_len, "%d", rs->rotport.timeout);
break; break;
case TOK_RETRY: case TOK_RETRY:
snprintf(val, val_len, "%d", rs->rotport.retry); SNPRINTF(val, val_len, "%d", rs->rotport.retry);
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
@ -401,7 +401,7 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->rotport.parm.serial.rate); SNPRINTF(val, val_len, "%d", rs->rotport.parm.serial.rate);
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
@ -410,7 +410,7 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->rotport.parm.serial.data_bits); SNPRINTF(val, val_len, "%d", rs->rotport.parm.serial.data_bits);
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
@ -419,7 +419,7 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val, int val_len)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
snprintf(val, val_len, "%d", rs->rotport.parm.serial.stop_bits); SNPRINTF(val, val_len, "%d", rs->rotport.parm.serial.stop_bits);
break; break;
case TOK_PARITY: case TOK_PARITY:
@ -485,23 +485,23 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val, int val_len)
break; break;
case TOK_MIN_AZ: case TOK_MIN_AZ:
snprintf(val, val_len, "%f", rs->min_az); SNPRINTF(val, val_len, "%f", rs->min_az);
break; break;
case TOK_MAX_AZ: case TOK_MAX_AZ:
snprintf(val, val_len, "%f", rs->max_az); SNPRINTF(val, val_len, "%f", rs->max_az);
break; break;
case TOK_MIN_EL: case TOK_MIN_EL:
snprintf(val, val_len, "%f", rs->min_el); SNPRINTF(val, val_len, "%f", rs->min_el);
break; break;
case TOK_MAX_EL: case TOK_MAX_EL:
snprintf(val, val_len, "%f", rs->max_el); SNPRINTF(val, val_len, "%f", rs->max_el);
break; break;
case TOK_SOUTH_ZERO: case TOK_SOUTH_ZERO:
snprintf(val, val_len, "%d", rs->south_zero); SNPRINTF(val, val_len, "%d", rs->south_zero);
break; break;
default: default:
@ -713,7 +713,7 @@ int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val)
{ {
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[32]; char tokenstr[32];
snprintf(tokenstr, sizeof(tokenstr), "%ld", token); SNPRINTF(tokenstr, sizeof(tokenstr), "%ld", token);
cfp = rot_confparam_lookup(rot, tokenstr); cfp = rot_confparam_lookup(rot, tokenstr);
if (!cfp) if (!cfp)

Wyświetl plik

@ -109,7 +109,7 @@ int rig_sprintf_mode(char *str, int nlen, rmode_t mode)
} }
int rig_sprintf_ant(char *str, int nlen, ant_t ant) int rig_sprintf_ant(char *str, int str_len, ant_t ant)
{ {
int i, len = 0; int i, len = 0;
char *ant_name; char *ant_name;
@ -118,7 +118,7 @@ int rig_sprintf_ant(char *str, int nlen, ant_t ant)
if (ant == RIG_ANT_NONE) if (ant == RIG_ANT_NONE)
{ {
sprintf(str, "ANT_NONE"); SNPRINTF(str, str_len, "ANT_NONE");
return 0; return 0;
} }
@ -149,7 +149,7 @@ int rig_sprintf_ant(char *str, int nlen, ant_t ant)
} }
len += sprintf(str + len, "%s ", ant_name); len += sprintf(str + len, "%s ", ant_name);
check_buffer_overflow(str, len, nlen); check_buffer_overflow(str, len, str_len);
} }
} }