diff --git a/ft8/packing.cpp b/ft8/packing.cpp index 30f5ea783..7be99f27d 100644 --- a/ft8/packing.cpp +++ b/ft8/packing.cpp @@ -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); } diff --git a/plugins/channelrx/demoddatv/leansdr/dvbs2.h b/plugins/channelrx/demoddatv/leansdr/dvbs2.h index 69ad0d315..9c17afec4 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvbs2.h +++ b/plugins/channelrx/demoddatv/leansdr/dvbs2.h @@ -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*)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, diff --git a/plugins/channelrx/demoddatv/leansdr/gui.h b/plugins/channelrx/demoddatv/leansdr/gui.h index 70f9c914f..00a4f08cd 100644 --- a/plugins/channelrx/demoddatv/leansdr/gui.h +++ b/plugins/channelrx/demoddatv/leansdr/gui.h @@ -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; diff --git a/plugins/channeltx/modpacket/packetmodgui.cpp b/plugins/channeltx/modpacket/packetmodgui.cpp index 8c281ac59..adc634962 100644 --- a/plugins/channeltx/modpacket/packetmodgui.cpp +++ b/plugins/channeltx/modpacket/packetmodgui.cpp @@ -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); } diff --git a/plugins/feature/ambe/ambeengine.cpp b/plugins/feature/ambe/ambeengine.cpp index 8f0211b85..ca8f66f61 100644 --- a/plugins/feature/ambe/ambeengine.cpp +++ b/plugins/feature/ambe/ambeengine.cpp @@ -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)); } } diff --git a/plugins/feature/rigctlserver/rigctlserverworker.cpp b/plugins/feature/rigctlserver/rigctlserverworker.cpp index d772226b1..2b02b2c0d 100644 --- a/plugins/feature/rigctlserver/rigctlserverworker.cpp +++ b/plugins/feature/rigctlserver/rigctlserverworker.cpp @@ -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)); } } diff --git a/plugins/samplesink/limesdroutput/limesdroutputgui.cpp b/plugins/samplesink/limesdroutput/limesdroutputgui.cpp index d77b6c0ec..c90d53e96 100644 --- a/plugins/samplesink/limesdroutput/limesdroutputgui.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutputgui.cpp @@ -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 &))); diff --git a/plugins/samplesink/usrpoutput/usrpoutputgui.cpp b/plugins/samplesink/usrpoutput/usrpoutputgui.cpp index 59bce9fd8..98b5e5b17 100644 --- a/plugins/samplesink/usrpoutput/usrpoutputgui.cpp +++ b/plugins/samplesink/usrpoutput/usrpoutputgui.cpp @@ -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 &))); diff --git a/sdrbase/util/serialutil.cpp b/sdrbase/util/serialutil.cpp index dd949603f..183718efd 100644 --- a/sdrbase/util/serialutil.cpp +++ b/sdrbase/util/serialutil.cpp @@ -44,7 +44,7 @@ void SerialUtil::getComPorts(std::vector& 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);