mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-06-11 19:12:32 -04:00
Replace sprintf by snprintf wherever possible
This commit is contained in:
parent
2e1411311b
commit
77b2b815b8
@ -82,7 +82,7 @@ std::string Packing::unpackcall(int x)
|
||||
|
||||
if (x <= 1002)
|
||||
{
|
||||
sprintf(tmp, "CQ %d", x - 3);
|
||||
snprintf(tmp, sizeof(tmp), "CQ %d", x - 3);
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ std::string Packing::unpackcall(int x)
|
||||
int ci3 = x / 27;
|
||||
x %= 27;
|
||||
int ci4 = x;
|
||||
sprintf(tmp, "CQ %c%c%c%c", c4[ci1], c4[ci2], c4[ci3], c4[ci4]);
|
||||
snprintf(tmp, sizeof(tmp), "CQ %c%c%c%c", c4[ci1], c4[ci2], c4[ci3], c4[ci4]);
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
@ -193,9 +193,9 @@ std::string Packing::unpackgrid15(int ng, int ir)
|
||||
char tmp[16];
|
||||
|
||||
if (db >= 0) {
|
||||
sprintf(tmp, "%s+%02d", ir ? "R" : "", db);
|
||||
snprintf(tmp, sizeof(tmp), "%s+%02d", ir ? "R" : "", db);
|
||||
} else {
|
||||
sprintf(tmp, "%s-%02d", ir ? "R" : "", 0 - db);
|
||||
snprintf(tmp, sizeof(tmp), "%s-%02d", ir ? "R" : "", 0 - db);
|
||||
}
|
||||
|
||||
return std::string(tmp);
|
||||
@ -396,7 +396,7 @@ std::string Packing::unpack_5(int a77[], std::string& call1str, std::string& cal
|
||||
i += 3;
|
||||
int qsonb = un64(a77, i, 11);
|
||||
char report[16];
|
||||
sprintf(report, "%d%04d", rst, qsonb);
|
||||
snprintf(report, sizeof(report), "%d%04d", rst, qsonb);
|
||||
i += 11;
|
||||
// g25
|
||||
int ng = un64(a77, i, 25);
|
||||
@ -467,9 +467,9 @@ std::string Packing::unpack_0_1(int a77[], std::string& call1str, std::string& c
|
||||
char tmp[32];
|
||||
|
||||
if (r >= 0) {
|
||||
sprintf(tmp, "+%02d", r);
|
||||
snprintf(tmp, sizeof(tmp), "+%02d", r);
|
||||
} else {
|
||||
sprintf(tmp, "-%02d", -r);
|
||||
snprintf(tmp, sizeof(tmp), "-%02d", -r);
|
||||
}
|
||||
|
||||
locstr = std::string(tmp);
|
||||
@ -553,7 +553,7 @@ std::string Packing::unpack_3(int a77[], std::string& call1str, std::string& cal
|
||||
else
|
||||
{
|
||||
char tmp[32];
|
||||
sprintf(tmp, "%04d", serial);
|
||||
snprintf(tmp, sizeof(tmp), "%04d", serial);
|
||||
serialstr = std::string(tmp);
|
||||
}
|
||||
|
||||
@ -571,7 +571,7 @@ std::string Packing::unpack_3(int a77[], std::string& call1str, std::string& cal
|
||||
}
|
||||
{
|
||||
char tmp[16];
|
||||
sprintf(tmp, "%d ", rst);
|
||||
snprintf(tmp, sizeof(tmp), "%d ", rst);
|
||||
msg += std::string(tmp);
|
||||
}
|
||||
|
||||
@ -634,7 +634,7 @@ std::string Packing::unpack_0_3(int a77[], int n3, std::string& call1str, std::s
|
||||
|
||||
{
|
||||
char tmp[16];
|
||||
sprintf(tmp, "%d%c ", n_transmitters + 1, clss + 'A');
|
||||
snprintf(tmp, sizeof(tmp), "%d%c ", n_transmitters + 1, clss + 'A');
|
||||
msg += std::string(tmp);
|
||||
}
|
||||
|
||||
@ -658,9 +658,9 @@ std::string Packing::unpack(int a77[], std::string& call1, std::string& call2, s
|
||||
char tmp[64];
|
||||
|
||||
if (i3 == 0) {
|
||||
sprintf(tmp, "%d.%d", i3, n3);
|
||||
snprintf(tmp, sizeof(tmp), "%d.%d", i3, n3);
|
||||
} else {
|
||||
sprintf(tmp, "%d", i3);
|
||||
snprintf(tmp, sizeof(tmp), "%d", i3);
|
||||
}
|
||||
|
||||
type = std::string(tmp);
|
||||
@ -714,7 +714,7 @@ std::string Packing::unpack(int a77[], std::string& call1, std::string& call2, s
|
||||
}
|
||||
|
||||
call1 = "UNK";
|
||||
sprintf(tmp, "UNK i3=%d n3=%d", i3, n3);
|
||||
snprintf(tmp, sizeof(tmp), "UNK i3=%d n3=%d", i3, n3);
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
|
@ -700,8 +700,9 @@ struct s2_frame_receiver : runnable
|
||||
|
||||
char *format() {
|
||||
static char buf[256];
|
||||
sprintf(
|
||||
snprintf(
|
||||
buf,
|
||||
sizeof(buf),
|
||||
"%9.2lf %+6.0f ppm %+3.0f ° %f",
|
||||
(double)((p-(std::complex<T>*)NULL)&262143)+mu, // Arbitrary wrap
|
||||
fw16*1e6/65536,
|
||||
@ -3516,11 +3517,11 @@ struct s2_fecdec_helper : runnable
|
||||
close(rx[0]);
|
||||
dup2(rx[1], 1);
|
||||
char max_trials_arg[16];
|
||||
sprintf(max_trials_arg, "%d", max_trials);
|
||||
snprintf(max_trials_arg, sizeof(max_trial_args), "%d", max_trials);
|
||||
char batch_size_arg[16];
|
||||
sprintf(batch_size_arg, "%d", batch_size);
|
||||
snprintf(batch_size_arg, sizeof(batch_size_args), "%d", batch_size);
|
||||
char mc_arg[16];
|
||||
sprintf(mc_arg, "%d", pls->modcod);
|
||||
snprintf(mc_arg, sizeof(mc_arg), "%d", pls->modcod);
|
||||
const char *sf_arg = pls->sf ? "--shortframes" : nullptr;
|
||||
const char *argv[] = {
|
||||
command,
|
||||
|
@ -368,7 +368,7 @@ struct slowmultiscope : runnable
|
||||
channel *c = &chans[i];
|
||||
g.setfg(c->spec.rgb[0], c->spec.rgb[1], c->spec.rgb[2]);
|
||||
char text[256];
|
||||
sprintf(text, c->spec.format, c->print_val);
|
||||
snprintf(text, sizeof(text), c->spec.format, c->print_val);
|
||||
g.transient_text(5, 20 + 16 * i, text);
|
||||
}
|
||||
run_gui();
|
||||
@ -445,7 +445,7 @@ struct slowmultiscope : runnable
|
||||
float ct = g.mx * samples_per_pixel / sample_freq;
|
||||
float tt = total_samples / sample_freq;
|
||||
char text[256];
|
||||
sprintf(text, "%.3f / %.3f s", ct, tt);
|
||||
snprintf(text, sizeof(text), "%.3f / %.3f s", ct, tt);
|
||||
g.setfg(255, 255, 255);
|
||||
g.transient_text(g.w * 3 / 4, 20, text);
|
||||
}
|
||||
@ -529,7 +529,7 @@ struct spectrumscope : runnable
|
||||
{
|
||||
char s[256];
|
||||
float f = 2.4e6 * (g.mx - g.w / 2) / g.w;
|
||||
sprintf(s, "%f", f);
|
||||
snprintf(s, sizeof(s), "%f", f);
|
||||
g.text(16, 16, s);
|
||||
}
|
||||
g.show();
|
||||
@ -637,7 +637,7 @@ struct rfscope : runnable
|
||||
char s[256];
|
||||
float freq = Fc + Fs * (g.mx - g.w / 2) / g.w / hzoom;
|
||||
float val = db0 + (float)((g.h - 1) - g.my) * dbrange / g.h;
|
||||
sprintf(s, "%f.3 Hz %f.2 dB", freq, val);
|
||||
snprintf(s, sizeof(s), "%f.3 Hz %f.2 dB", freq, val);
|
||||
g.setfg(255, 255, 255);
|
||||
g.text(16, 16, s);
|
||||
}
|
||||
@ -726,7 +726,7 @@ struct genscope : runnable
|
||||
g.line(pc->spec.r.x - dx, pc->spec.r.y - dy,
|
||||
pc->spec.r.x + dx, pc->spec.r.y + dy);
|
||||
char txt[16];
|
||||
sprintf(txt, "%d", (int)last);
|
||||
snprintf(txt, sizeof(txt), "%d", (int)last);
|
||||
g.text(pc->spec.r.x + 5, pc->spec.r.y - 2, txt);
|
||||
}
|
||||
struct timeval newtv;
|
||||
|
@ -258,8 +258,8 @@ void PacketModGUI::on_insertPosition_clicked()
|
||||
longFrac = round(longitude);
|
||||
|
||||
// Insert position with house symbol (-) in to data field
|
||||
sprintf(latBuf, "%02d%02d.%02d%c", latDeg, latMin, latFrac, latNorth ? 'N' : 'S');
|
||||
sprintf(longBuf, "%03d%02d.%02d%c", longDeg, longMin, longFrac, longEast ? 'E' : 'W');
|
||||
snprintf(latBuf, sizeof(latBuf), "%02d%02d.%02d%c", latDeg, latMin, latFrac, latNorth ? 'N' : 'S');
|
||||
snprintf(longBuf, sizeof(longBuf), "%03d%02d.%02d%c", longDeg, longMin, longFrac, longEast ? 'E' : 'W');
|
||||
QString packet = QString("%1/%2-").arg(latBuf).arg(longBuf);
|
||||
ui->packet->insert(packet);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void AMBEEngine::getComList()
|
||||
// Arbitrarily set the list to the 20 first COM ports
|
||||
for (int i = 1; i <= 20; i++)
|
||||
{
|
||||
sprintf(comCStr, "COM%d", i);
|
||||
snprintf(comCStr, sizeof(comCStr), "COM%d", i);
|
||||
m_comList.push_back(std::string(comCStr));
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ void RigCtlServerWorker::getCommand()
|
||||
// Set frequency
|
||||
double targetFrequency = atof(cmd[0] == 'F' ? &cmd[2] : &cmd[9]);
|
||||
setFrequency(targetFrequency, rigCtlRC);
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
else if (!strncmp(cmd, "f", 1) || !strncmp(cmd, "get_freq", 8))
|
||||
{
|
||||
@ -211,9 +211,9 @@ void RigCtlServerWorker::getCommand()
|
||||
double frequency;
|
||||
|
||||
if (getFrequency(frequency, rigCtlRC)) {
|
||||
sprintf(response, "%u\n", (unsigned int) frequency);
|
||||
snprintf(response, sizeof(response), "%u\n", (unsigned int) frequency);
|
||||
} else {
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(cmd, "M ?", 3) || !(strncmp(cmd, "set_mode ?", 10)))
|
||||
@ -263,11 +263,11 @@ void RigCtlServerWorker::getCommand()
|
||||
if (m_modeMap[i].modem != nullptr)
|
||||
{
|
||||
changeModem(targetMode, targetModem, targetBW, rigCtlRC);
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(response, "RPRT %d\n", RIG_EINVAL);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", RIG_EINVAL);
|
||||
m_clientConnection->write(response, strlen(response));
|
||||
}
|
||||
}
|
||||
@ -280,27 +280,27 @@ void RigCtlServerWorker::getCommand()
|
||||
if (getMode(&mode, passband, rigCtlRC))
|
||||
{
|
||||
if (passband < 0) {
|
||||
sprintf(response, "%s\n", mode);
|
||||
snprintf(response, sizeof(response), "%s\n", mode);
|
||||
} else {
|
||||
sprintf(response, "%s %u\n", mode, (unsigned int) passband);
|
||||
snprintf(response, sizeof(response), "%s %u\n", mode, (unsigned int) passband);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(cmd, "set_powerstat 0", 15))
|
||||
{
|
||||
// Power off radio
|
||||
setPowerOff(rigCtlRC);
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
else if (!strncmp(cmd, "set_powerstat 1", 15))
|
||||
{
|
||||
// Power on radio
|
||||
setPowerOn(rigCtlRC);
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
else if (!strncmp(cmd, "get_powerstat", 13))
|
||||
{
|
||||
@ -309,20 +309,20 @@ void RigCtlServerWorker::getCommand()
|
||||
if (getPower(power, rigCtlRC))
|
||||
{
|
||||
if (power) {
|
||||
sprintf(response, "1\n");
|
||||
snprintf(response, sizeof(response), "1\n");
|
||||
} else {
|
||||
sprintf(response, "0\n");
|
||||
snprintf(response, sizeof(response), "0\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(response, "RPRT %d\n", rigCtlRC);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", rigCtlRC);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unimplemented command
|
||||
sprintf(response, "RPRT %d\n", RIG_ENIMPL);
|
||||
snprintf(response, sizeof(response), "RPRT %d\n", RIG_ENIMPL);
|
||||
m_clientConnection->write(response, strlen(response));
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ LimeSDROutputGUI::LimeSDROutputGUI(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
displaySettings();
|
||||
|
||||
char recFileNameCStr[30];
|
||||
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceUISet->m_deviceAPI->getDeviceUID());
|
||||
snprintf(recFileNameCStr, sizeof(recFileNameCStr), "test_%d.sdriq", m_deviceUISet->m_deviceAPI->getDeviceUID());
|
||||
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
||||
|
@ -82,7 +82,7 @@ USRPOutputGUI::USRPOutputGUI(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
displaySettings();
|
||||
|
||||
char recFileNameCStr[30];
|
||||
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceUISet->m_deviceAPI->getDeviceUID());
|
||||
snprintf(recFileNameCStr, sizeof(recFileNameCStr), "test_%d.sdriq", m_deviceUISet->m_deviceAPI->getDeviceUID());
|
||||
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
||||
|
@ -44,7 +44,7 @@ void SerialUtil::getComPorts(std::vector<std::string>& comPorts, const std::stri
|
||||
|
||||
for (int i = 0; i<255; i++) // checking ports from COM0 to COM255
|
||||
{
|
||||
sprintf(portName, "COM%d", i);
|
||||
snprintf(portName, sizeof(portName), "COM%d", i);
|
||||
|
||||
test = QueryDosDeviceA((LPCSTR)portName, (LPSTR)lpTargetPath, 5000);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user