Change sprintf to snprint in rigs/kit

https://github.com/Hamlib/Hamlib/issues/857
pull/928/head
Mike Black W9MDB 2022-01-15 23:29:19 -06:00
rodzic 939b3e3885
commit 6a516b4a34
9 zmienionych plików z 60 dodań i 30 usunięć

Wyświetl plik

@ -250,7 +250,7 @@ int dds60_set_conf(RIG *rig, token_t token, const char *val)
* Assumes rig!=NULL, rig->state.priv!=NULL * Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value. * and val points to a buffer big enough to hold the conf value.
*/ */
int dds60_get_conf(RIG *rig, token_t token, char *val) int dds60_get_conf2(RIG *rig, token_t token, char *val, int val_len)
{ {
struct dds60_priv_data *priv; struct dds60_priv_data *priv;
@ -259,19 +259,19 @@ int dds60_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%"PRIfreq, priv->osc_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->osc_freq);
break; break;
case TOK_IFMIXFREQ: case TOK_IFMIXFREQ:
sprintf(val, "%"PRIfreq, priv->if_mix_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->if_mix_freq);
break; break;
case TOK_MULTIPLIER: case TOK_MULTIPLIER:
sprintf(val, "%d", priv->multiplier); SNPRINTF(val, val_len, "%d", priv->multiplier);
break; break;
case TOK_PHASE_MOD: case TOK_PHASE_MOD:
sprintf(val, "%f", priv->phase_step * PHASE_INCR); SNPRINTF(val, val_len, "%f", priv->phase_step * PHASE_INCR);
break; break;
default: default:
@ -281,6 +281,11 @@ int dds60_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int dds60_get_conf(RIG *rig, token_t token, char *val)
{
return dds60_get_conf2(rig, token, val, 128);
}
#define DATA 0x01 /* d0 */ #define DATA 0x01 /* d0 */
#define CLOCK 0x02 /* d1 */ #define CLOCK 0x02 /* d1 */

Wyświetl plik

@ -248,7 +248,7 @@ int drt1_set_conf(RIG *rig, token_t token, const char *val)
* Assumes rig!=NULL, rig->state.priv!=NULL * Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value. * and val points to a buffer big enough to hold the conf value.
*/ */
int drt1_get_conf(RIG *rig, token_t token, char *val) int drt1_get_conf2(RIG *rig, token_t token, char *val, int val_len)
{ {
struct drt1_priv_data *priv; struct drt1_priv_data *priv;
@ -257,19 +257,19 @@ int drt1_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%"PRIfreq, priv->osc_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->osc_freq);
break; break;
case TOK_REFMULT: case TOK_REFMULT:
sprintf(val, "%u", priv->ref_mult); SNPRINTF(val, val_len, "%u", priv->ref_mult);
break; break;
case TOK_IFMIXFREQ: case TOK_IFMIXFREQ:
sprintf(val, "%"PRIfreq, priv->if_mix_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->if_mix_freq);
break; break;
case TOK_PUMPCRNT: case TOK_PUMPCRNT:
sprintf(val, "%u", priv->pump_crrnt); SNPRINTF(val, val_len, "%u", priv->pump_crrnt);
break; break;
default: default:
@ -279,6 +279,11 @@ int drt1_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int drt1_get_conf(RIG *rig, token_t token, char *val)
{
return drt1_get_conf2(rig, token, val, 128);
}
/* /*

Wyświetl plik

@ -678,7 +678,7 @@ const char *dwt_get_info(RIG *rig)
/* always succeeds since libusb-1.0.16 */ /* always succeeds since libusb-1.0.16 */
libusb_get_device_descriptor(libusb_get_device(udh), &desc); libusb_get_device_descriptor(libusb_get_device(udh), &desc);
sprintf(buf, "Dev %04d", desc.bcdDevice); SNPRINTF(buf, sizeof(buf), "Dev %04d", desc.bcdDevice);
return buf; return buf;
} }

Wyświetl plik

@ -230,7 +230,7 @@ int elektor304_set_conf(RIG *rig, token_t token, const char *val)
* Assumes rig!=NULL, rig->state.priv!=NULL * Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value. * and val points to a buffer big enough to hold the conf value.
*/ */
int elektor304_get_conf(RIG *rig, token_t token, char *val) int elektor304_get_conf2(RIG *rig, token_t token, char *val, int val_len)
{ {
struct elektor304_priv_data *priv; struct elektor304_priv_data *priv;
@ -239,11 +239,11 @@ int elektor304_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%"PRIfreq, priv->osc_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->osc_freq);
break; break;
case TOK_IFMIXFREQ: case TOK_IFMIXFREQ:
sprintf(val, "%"PRIfreq, priv->if_mix_freq); SNPRINTF(val, val_len, "%"PRIfreq, priv->if_mix_freq);
break; break;
default: default:
@ -253,6 +253,11 @@ int elektor304_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int elektor304_get_conf(RIG *rig, token_t token, char *val)
{
return elektor304_get_conf2(rig, token, val, 128);
}
#define AD_DELAY 4000 #define AD_DELAY 4000
/* /*

Wyświetl plik

@ -361,7 +361,7 @@ const char *elektor507_get_info(RIG *rig)
{ {
static char buf[64]; static char buf[64];
sprintf(buf, "Elektor SDR USB w/ FTDI DLL"); SNPRINTF(buf, sizeof(buf), "Elektor SDR USB w/ FTDI DLL");
return buf; return buf;
} }
@ -436,7 +436,7 @@ const char *elektor507_get_info(RIG *rig)
/* always succeeds since libusb-1.0.16 */ /* always succeeds since libusb-1.0.16 */
libusb_get_device_descriptor(libusb_get_device(udh), &desc); libusb_get_device_descriptor(libusb_get_device(udh), &desc);
sprintf(buf, "USB dev %04d", desc.bcdDevice); SNPRINTF(buf, sizeof(buf), "USB dev %04d", desc.bcdDevice);
return buf; return buf;
} }
@ -670,7 +670,7 @@ int elektor507_set_conf(RIG *rig, token_t token, const char *val)
return RIG_OK; return RIG_OK;
} }
int elektor507_get_conf(RIG *rig, token_t token, char *val) int elektor507_get_conf2(RIG *rig, token_t token, char *val, val_len)
{ {
struct elektor507_priv_data *priv; struct elektor507_priv_data *priv;
@ -679,11 +679,11 @@ int elektor507_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%"PRIfreq, priv->osc_freq * kHz(1)); SNPRINTF(val, val_len, "%"PRIfreq, priv->osc_freq * kHz(1));
break; break;
case TOK_XTALCAL: case TOK_XTALCAL:
sprintf(val, "%u", priv->xtal_cal); SNPRINTF(val, val_len, "%u", priv->xtal_cal);
break; break;
default: default:
@ -693,6 +693,11 @@ int elektor507_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int elektor507_get_conf(RIG *rig, token_t token, char *val)
{
return elektor507_get_conf2(rig, token, val, 128);
}
int elektor507_open(RIG *rig) int elektor507_open(RIG *rig)

Wyświetl plik

@ -319,7 +319,7 @@ const char *funcube_get_info(RIG *rig)
/* always succeeds since libusb-1.0.16 */ /* always succeeds since libusb-1.0.16 */
libusb_get_device_descriptor(libusb_get_device(udh), &desc); libusb_get_device_descriptor(libusb_get_device(udh), &desc);
sprintf(buf, "Dev %04d", desc.bcdDevice); SNPRINTF(buf, sizeof(buf), "Dev %04d", desc.bcdDevice);
return buf; return buf;
} }

Wyświetl plik

@ -260,7 +260,7 @@ int hiqsdr_set_conf(RIG *rig, token_t token, const char *val)
* Assumes rig!=NULL, rig->state.priv!=NULL * Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value. * and val points to a buffer big enough to hold the conf value.
*/ */
int hiqsdr_get_conf(RIG *rig, token_t token, char *val) int hiqsdr_get_conf2(RIG *rig, token_t token, char *val, int val_len)
{ {
struct hiqsdr_priv_data *priv; struct hiqsdr_priv_data *priv;
struct rig_state *rs; struct rig_state *rs;
@ -271,11 +271,11 @@ int hiqsdr_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%f", priv->ref_clock); SNPRINTF(val, val_len, "%f", priv->ref_clock);
break; break;
case TOK_SAMPLE_RATE: case TOK_SAMPLE_RATE:
sprintf(val, "%d", priv->sample_rate); SNPRINTF(val, val_len, "%d", priv->sample_rate);
break; break;
default: default:
@ -285,6 +285,11 @@ int hiqsdr_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int hiqsdr_get_conf(RIG *rig, token_t token, char *val)
{
return hiqsdr_get_conf2(rig, token, val, 128);
}
int hiqsdr_init(RIG *rig) int hiqsdr_init(RIG *rig)
{ {
struct hiqsdr_priv_data *priv; struct hiqsdr_priv_data *priv;

Wyświetl plik

@ -48,7 +48,7 @@ static int miniVNA_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
rig_flush(&rig->state.rigport); rig_flush(&rig->state.rigport);
sprintf(cmdstr, "0\r%lu\r1\r0\r", (unsigned long int)(freq * DDS_RATIO)); SNPRINTF(cmdstr, sizeof(cmdstr), "0\r%lu\r1\r0\r", (unsigned long int)(freq * DDS_RATIO));
retval = write_block(&rig->state.rigport, (unsigned char *) cmdstr, strlen(cmdstr)); retval = write_block(&rig->state.rigport, (unsigned char *) cmdstr, strlen(cmdstr));

Wyświetl plik

@ -929,7 +929,7 @@ int si570xxxusb_set_conf(RIG *rig, token_t token, const char *val)
return RIG_OK; return RIG_OK;
} }
int si570xxxusb_get_conf(RIG *rig, token_t token, char *val) int si570xxxusb_get_conf2(RIG *rig, token_t token, char *val, int val_len)
{ {
struct si570xxxusb_priv_data *priv; struct si570xxxusb_priv_data *priv;
@ -938,19 +938,19 @@ int si570xxxusb_get_conf(RIG *rig, token_t token, char *val)
switch (token) switch (token)
{ {
case TOK_OSCFREQ: case TOK_OSCFREQ:
sprintf(val, "%"PRIfreq, (freq_t)(priv->osc_freq * 1e6)); SNPRINTF(val, val_len, "%"PRIfreq, (freq_t)(priv->osc_freq * 1e6));
break; break;
case TOK_MULTIPLIER: case TOK_MULTIPLIER:
sprintf(val, "%f", priv->multiplier); SNPRINTF(val, val_len, "%f", priv->multiplier);
break; break;
case TOK_I2C_ADDR: case TOK_I2C_ADDR:
sprintf(val, "%x", priv->i2c_addr); SNPRINTF(val, val_len, "%x", priv->i2c_addr);
break; break;
case TOK_BPF: case TOK_BPF:
sprintf(val, "%d", priv->bpf); SNPRINTF(val, val_len, "%d", priv->bpf);
break; break;
default: default:
@ -960,6 +960,11 @@ int si570xxxusb_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
int si570xxxusb_get_conf(RIG *rig, token_t token, char *val)
{
return si570xxusb_get_conf2(rig, token val, 128);
}
static int setBPF(RIG *rig, int enable) static int setBPF(RIG *rig, int enable)
{ {
@ -1100,7 +1105,7 @@ const char *si570xxxusb_get_info(RIG *rig)
/* always succeeds since libusb-1.0.16 */ /* always succeeds since libusb-1.0.16 */
libusb_get_device_descriptor(libusb_get_device(udh), &desc); libusb_get_device_descriptor(libusb_get_device(udh), &desc);
sprintf(buf, "USB dev %04d, version: %d.%d", desc.bcdDevice, buffer[1], SNPRINTF(buf, sizeof(buf), "USB dev %04d, version: %d.%d", desc.bcdDevice, buffer[1],
buffer[0]); buffer[0]);
return buf; return buf;