kopia lustrzana https://github.com/Hamlib/Hamlib
Add SPRINTF macro to use instead of sprintf for automatic detection of buffer limit exceeded
https://github.com/Hamlib/Hamlib/issues/857pull/928/head
rodzic
18ca415b41
commit
c88e32e0d6
|
@ -233,7 +233,7 @@ int kpa_set_freq(AMP *amp, freq_t freq)
|
|||
|
||||
if (!amp) { return -RIG_EINVAL; }
|
||||
|
||||
sprintf(cmd, "^FR%05ld;", (long)freq / 1000);
|
||||
SNPRINTF(cmd, sizeof(cmd), "^FR%05ld;", (long)freq / 1000);
|
||||
retval = kpa_transaction(amp, cmd, NULL, 0);
|
||||
|
||||
if (retval != RIG_OK) { return retval; }
|
||||
|
@ -486,7 +486,7 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val)
|
|||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_ERR, "%s unknown fault from %s\n", __func__, responsebuf);
|
||||
sprintf(priv->tmpbuf, "Unknown fault code=0x%02x", fault);
|
||||
SNPRINTF(priv->tmpbuf, sizeof(priv->tmpbuf), "Unknown fault code=0x%02x", fault);
|
||||
val->s = priv->tmpbuf;
|
||||
return RIG_OK;
|
||||
|
||||
|
|
|
@ -3158,6 +3158,9 @@ extern HAMLIB_EXPORT_VAR(char) debugmsgsave3[DEBUGMSGSAVE_SIZE]; // last-2 debu
|
|||
#define ELAPSED1 struct timespec __begin; elapsed_ms(&__begin, HAMLIB_ELAPSED_SET);
|
||||
#define ELAPSED2 rig_debug(RIG_DEBUG_TRACE, "%s: elapsed=%.0lfms\n", __func__, elapsed_ms(&__begin, HAMLIB_ELAPSED_GET));
|
||||
|
||||
// use this instead of snprintf for automatic detection of buffer limit
|
||||
#define SNPRINTF(s,n,...) { snprintf(s,n,##__VA_ARGS__);if (strlen(s) >= n-1) printf("%s(%d): buffer limit reached\n", __func__, __LINE__); }
|
||||
|
||||
extern HAMLIB_EXPORT(void)
|
||||
rig_debug HAMLIB_PARAMS((enum rig_debug_level_e debug_level,
|
||||
const char *fmt, ...));
|
||||
|
|
Ładowanie…
Reference in New Issue