diff --git a/src/dlg_filter.cpp b/src/dlg_filter.cpp index f0986440..5d9e1ebb 100644 --- a/src/dlg_filter.cpp +++ b/src/dlg_filter.cpp @@ -857,11 +857,13 @@ void FilterDlg::adjRunTimeSpkOutFilter(void) { void FilterDlg::plotFilterSpectrum(EQ *eqBass, EQ *eqMid, EQ *eqTreble, EQ* eqVol, PlotSpectrum* freqRespPlot, float *magdB) { + const int MAX_ARG_STORAGE_LEN = 80; + char *argBass[10]; char *argTreble[10]; char *argMid[10]; char *argVol[10]; - char argstorage[10][80]; + char argstorage[10][MAX_ARG_STORAGE_LEN]; float magBass[F_MAG_N]; float magTreble[F_MAG_N]; float magMid[F_MAG_N]; @@ -874,29 +876,29 @@ void FilterDlg::plotFilterSpectrum(EQ *eqBass, EQ *eqMid, EQ *eqTreble, EQ* eqVo argMid[i] = &argstorage[i][0]; argVol[i] = &argstorage[i][0]; } - sprintf(argBass[0], "bass"); - sprintf(argBass[1], "%f", eqBass->gaindB+1E-6); - sprintf(argBass[2], "%f", eqBass->freqHz); + snprintf(argBass[0], MAX_ARG_STORAGE_LEN, "bass"); + snprintf(argBass[1], MAX_ARG_STORAGE_LEN, "%f", eqBass->gaindB+1E-6); + snprintf(argBass[2], MAX_ARG_STORAGE_LEN, "%f", eqBass->freqHz); calcFilterSpectrum(magBass, 2, argBass); - sprintf(argTreble[0], "treble"); - sprintf(argTreble[1], "%f", eqTreble->gaindB+1E-6); - sprintf(argTreble[2], "%f", eqTreble->freqHz); + snprintf(argTreble[0], MAX_ARG_STORAGE_LEN, "treble"); + snprintf(argTreble[1], MAX_ARG_STORAGE_LEN, "%f", eqTreble->gaindB+1E-6); + snprintf(argTreble[2], MAX_ARG_STORAGE_LEN, "%f", eqTreble->freqHz); calcFilterSpectrum(magTreble, 2, argTreble); - sprintf(argMid[0], "equalizer"); - sprintf(argMid[1], "%f", eqMid->freqHz); - sprintf(argMid[2], "%f", eqMid->Q); - sprintf(argMid[3], "%f", eqMid->gaindB+1E-6); + snprintf(argMid[0], MAX_ARG_STORAGE_LEN, "equalizer"); + snprintf(argMid[1], MAX_ARG_STORAGE_LEN, "%f", eqMid->freqHz); + snprintf(argMid[2], MAX_ARG_STORAGE_LEN, "%f", eqMid->Q); + snprintf(argMid[3], MAX_ARG_STORAGE_LEN, "%f", eqMid->gaindB+1E-6); calcFilterSpectrum(magMid, 3, argMid); - sprintf(argVol[0], "vol"); - sprintf(argVol[1], "%f", eqVol->gaindB); - sprintf(argVol[2], "%s", "dB"); - sprintf(argVol[3], "%f", 0.05); + snprintf(argVol[0], MAX_ARG_STORAGE_LEN, "vol"); + snprintf(argVol[1], MAX_ARG_STORAGE_LEN, "%f", eqVol->gaindB); + snprintf(argVol[2], MAX_ARG_STORAGE_LEN, "%s", "dB"); + snprintf(argVol[3], MAX_ARG_STORAGE_LEN, "%f", 0.05); calcFilterSpectrum(magVol, 3, argVol); diff --git a/src/dlg_options.cpp b/src/dlg_options.cpp index fff87c17..3bd53eed 100644 --- a/src/dlg_options.cpp +++ b/src/dlg_options.cpp @@ -885,7 +885,7 @@ void OptionsDlg::OnFifoReset(wxCommandEvent& event) void OptionsDlg::OnUDPTest(wxCommandEvent& event) { char s[80]; - sprintf(s, "hello from FreeDV!"); + snprintf(s, 80, "hello from FreeDV!"); UDPSend(wxGetApp().m_udp_port, s, strlen(s)+1); } @@ -975,22 +975,24 @@ void OptionsDlg::OnMultipleRxEnable(wxCommandEvent& event) } void OptionsDlg::DisplayFifoPACounters() { - char fifo_counters[256]; + const int STR_LENGTH = 256; + + char fifo_counters[STR_LENGTH]; - sprintf(fifo_counters, "Fifos: infull1: %d outempty1: %d infull2: %d outempty2: %d", g_infifo1_full, g_outfifo1_empty, g_infifo2_full, g_outfifo2_empty); + snprintf(fifo_counters, STR_LENGTH, "Fifos: infull1: %d outempty1: %d infull2: %d outempty2: %d", g_infifo1_full, g_outfifo1_empty, g_infifo2_full, g_outfifo2_empty); wxString fifo_counters_string(fifo_counters); m_textFifos->SetLabel(fifo_counters_string); - char pa_counters1[256]; + char pa_counters1[STR_LENGTH]; // input: underflow overflow output: underflow overflow - sprintf(pa_counters1, "Audio1: inUnderflow: %d inOverflow: %d outUnderflow %d outOverflow %d", g_AEstatus1[0], g_AEstatus1[1], g_AEstatus1[2], g_AEstatus1[3]); + snprintf(pa_counters1, STR_LENGTH, "Audio1: inUnderflow: %d inOverflow: %d outUnderflow %d outOverflow %d", g_AEstatus1[0], g_AEstatus1[1], g_AEstatus1[2], g_AEstatus1[3]); wxString pa_counters1_string(pa_counters1); m_textPA1->SetLabel(pa_counters1_string); - char pa_counters2[256]; + char pa_counters2[STR_LENGTH]; // input: underflow overflow output: underflow overflow - sprintf(pa_counters2, "Audio2: inUnderflow: %d inOverflow: %d outUnderflow %d outOverflow %d", g_AEstatus2[0], g_AEstatus2[1], g_AEstatus2[2], g_AEstatus2[3]); + snprintf(pa_counters2, STR_LENGTH, "Audio2: inUnderflow: %d inOverflow: %d outUnderflow %d outOverflow %d", g_AEstatus2[0], g_AEstatus2[1], g_AEstatus2[2], g_AEstatus2[3]); wxString pa_counters2_string(pa_counters2); m_textPA2->SetLabel(pa_counters2_string); } diff --git a/src/eq.cpp b/src/eq.cpp index 832ee82b..c0768af1 100644 --- a/src/eq.cpp +++ b/src/eq.cpp @@ -10,8 +10,10 @@ void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float gaindB, float Q, int sampleRate) { + const int STR_LENGTH = 80; + char *arg[SBQ_MAX_ARGS]; - char argstorage[SBQ_MAX_ARGS][80]; + char argstorage[SBQ_MAX_ARGS][STR_LENGTH]; int i, argc; assert((strcmp(filterType, "bass") == 0) || @@ -26,27 +28,27 @@ void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float g argc = 0; if ((strcmp(filterType, "bass") == 0) || (strcmp(filterType, "treble") == 0)) { - sprintf(arg[argc++], "%s", filterType); - sprintf(arg[argc++], "%f", gaindB+1E-6); - sprintf(arg[argc++], "%f", freqHz); - sprintf(arg[argc++], "%d", sampleRate); + snprintf(arg[argc++], STR_LENGTH, "%s", filterType); + snprintf(arg[argc++], STR_LENGTH, "%f", gaindB+1E-6); + snprintf(arg[argc++], STR_LENGTH, "%f", freqHz); + snprintf(arg[argc++], STR_LENGTH, "%d", sampleRate); } if (strcmp(filterType, "equalizer") == 0) { - sprintf(arg[argc++], "%s", filterType); - sprintf(arg[argc++], "%f", freqHz); - sprintf(arg[argc++], "%f", Q); - sprintf(arg[argc++], "%f", gaindB+1E-6); - sprintf(arg[argc++], "%d", sampleRate); + snprintf(arg[argc++], STR_LENGTH, "%s", filterType); + snprintf(arg[argc++], STR_LENGTH, "%f", freqHz); + snprintf(arg[argc++], STR_LENGTH, "%f", Q); + snprintf(arg[argc++], STR_LENGTH, "%f", gaindB+1E-6); + snprintf(arg[argc++], STR_LENGTH, "%d", sampleRate); } if (strcmp(filterType, "vol") == 0) { - sprintf(arg[argc++], "%s", filterType); - sprintf(arg[argc++], "%f", gaindB); - sprintf(arg[argc++], "%s", "dB"); - sprintf(arg[argc++], "%f", 0.05); // to prevent clipping - sprintf(arg[argc++], "%d", sampleRate); + snprintf(arg[argc++], STR_LENGTH, "%s", filterType); + snprintf(arg[argc++], STR_LENGTH, "%f", gaindB); + snprintf(arg[argc++], STR_LENGTH, "%s", "dB"); + snprintf(arg[argc++], STR_LENGTH, "%f", 0.05); // to prevent clipping + snprintf(arg[argc++], STR_LENGTH, "%d", sampleRate); } assert(argc <= SBQ_MAX_ARGS); diff --git a/src/main.cpp b/src/main.cpp index 5d1b7e1e..40fe56a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -406,7 +406,7 @@ void MainFrame::loadConfiguration_() g_txLevel = pConfig->Read(wxT("/Audio/transmitLevel"), (int)0); char fmt[15]; m_sliderTxLevel->SetValue(g_txLevel); - sprintf(fmt, "%0.1f dB", (double)g_txLevel / 10.0); + snprintf(fmt, 15, "%0.1f dB", (double)g_txLevel / 10.0); wxString fmtString(fmt); m_txtTxLevelNum->SetLabel(fmtString); @@ -589,7 +589,7 @@ setDefaultMode: // squelch settings char sqsnr[15]; m_sliderSQ->SetValue((int)((g_SquelchLevel+5.0)*2.0)); - sprintf(sqsnr, "%4.1f dB", g_SquelchLevel); + snprintf(sqsnr, 15, "%4.1f dB", g_SquelchLevel); wxString sqsnr_string(sqsnr); m_textSQ->SetLabel(sqsnr_string); m_ckboxSQ->SetValue(g_SquelchActive); @@ -1197,7 +1197,7 @@ void MainFrame::OnTimer(wxTimerEvent &evt) if (snr_limited < -5.0) snr_limited = -5.0; if (snr_limited > 20.0) snr_limited = 20.0; char snr[15]; - sprintf(snr, "%4.1f", g_snr); + snprintf(snr, 15, "%4.1f", g_snr); //fprintf(stderr, "g_mode: %d snr_est: %f m_snrBeta: %f g_snr: %f snr_limited: %f\n", g_mode, g_stats.snr_est, m_snrBeta, g_snr, snr_limited); @@ -1444,27 +1444,30 @@ void MainFrame::OnTimer(wxTimerEvent &evt) // update stats on main page - char mode[80], bits[80], errors[80], ber[80], resyncs[80], clockoffset[80], freqoffset[80], syncmetric[80]; - sprintf(mode, "Mode: %s", freedvInterface.getCurrentModeStr()); wxString modeString(mode); m_textCurrentDecodeMode->SetLabel(modeString); - sprintf(bits, "Bits: %d", freedvInterface.getTotalBits()); wxString bits_string(bits); m_textBits->SetLabel(bits_string); - sprintf(errors, "Errs: %d", freedvInterface.getTotalBitErrors()); wxString errors_string(errors); m_textErrors->SetLabel(errors_string); + const int STR_LENGTH = 80; + char + mode[STR_LENGTH], bits[STR_LENGTH], errors[STR_LENGTH], ber[STR_LENGTH], + resyncs[STR_LENGTH], clockoffset[STR_LENGTH], freqoffset[STR_LENGTH], syncmetric[STR_LENGTH]; + snprintf(mode, STR_LENGTH, "Mode: %s", freedvInterface.getCurrentModeStr()); wxString modeString(mode); m_textCurrentDecodeMode->SetLabel(modeString); + snprintf(bits, STR_LENGTH, "Bits: %d", freedvInterface.getTotalBits()); wxString bits_string(bits); m_textBits->SetLabel(bits_string); + snprintf(errors, STR_LENGTH, "Errs: %d", freedvInterface.getTotalBitErrors()); wxString errors_string(errors); m_textErrors->SetLabel(errors_string); float b = (float)freedvInterface.getTotalBitErrors()/(1E-6+freedvInterface.getTotalBits()); - sprintf(ber, "BER: %4.3f", b); wxString ber_string(ber); m_textBER->SetLabel(ber_string); - sprintf(resyncs, "Resyncs: %d", g_resyncs); wxString resyncs_string(resyncs); m_textResyncs->SetLabel(resyncs_string); + snprintf(ber, STR_LENGTH, "BER: %4.3f", b); wxString ber_string(ber); m_textBER->SetLabel(ber_string); + snprintf(resyncs, STR_LENGTH, "Resyncs: %d", g_resyncs); wxString resyncs_string(resyncs); m_textResyncs->SetLabel(resyncs_string); - sprintf(freqoffset, "FrqOff: %3.1f", freedvInterface.getCurrentRxModemStats()->foff); + snprintf(freqoffset, STR_LENGTH, "FrqOff: %3.1f", freedvInterface.getCurrentRxModemStats()->foff); wxString freqoffset_string(freqoffset); m_textFreqOffset->SetLabel(freqoffset_string); - sprintf(syncmetric, "Sync: %3.2f", freedvInterface.getCurrentRxModemStats()->sync_metric); + snprintf(syncmetric, STR_LENGTH, "Sync: %3.2f", freedvInterface.getCurrentRxModemStats()->sync_metric); wxString syncmetric_string(syncmetric); m_textSyncMetric->SetLabel(syncmetric_string); // Codec 2 700C/D/E & 800XA VQ "auto EQ" equaliser variance auto var = freedvInterface.getVariance(); - char var_str[80]; sprintf(var_str, "Var: %4.1f", var); + char var_str[STR_LENGTH]; snprintf(var_str, STR_LENGTH, "Var: %4.1f", var); wxString var_string(var_str); m_textCodec2Var->SetLabel(var_string); if (g_State) { - sprintf(clockoffset, "ClkOff: %+-d", (int)round(freedvInterface.getCurrentRxModemStats()->clock_offset*1E6) % 10000); + snprintf(clockoffset, STR_LENGTH, "ClkOff: %+-d", (int)round(freedvInterface.getCurrentRxModemStats()->clock_offset*1E6) % 10000); wxString clockoffset_string(clockoffset); m_textClockOffset->SetLabel(clockoffset_string); // update error pattern plots if supported @@ -2672,9 +2675,9 @@ bool MainFrame::validateSoundCardSetup() int MainFrame::PollUDP(void) { // this will block until message received, so we put it in it's own thread - + const int STR_LENGTH = 80; char buf[1024]; - char reply[80]; + char reply[STR_LENGTH]; size_t n = m_udp_sock->RecvFrom(m_udp_addr, buf, sizeof(buf)).LastCount(); if (n) { @@ -2687,14 +2690,14 @@ int MainFrame::PollUDP(void) // for security only accept commands from local host - sprintf(reply,"nope\n"); + snprintf(reply, STR_LENGTH, "nope\n"); if (ipaddr.Cmp(_("127.0.0.1")) == 0) { // process commands if (bufstr.Cmp(_("restore")) == 0) { m_schedule_restore = true; // Make Restore happen in main thread to avoid crashing - sprintf(reply,"ok\n"); + snprintf(reply, STR_LENGTH, "ok\n"); } wxString itemToSet, val; @@ -2703,19 +2706,19 @@ int MainFrame::PollUDP(void) // note: if options dialog is open this will get overwritten wxGetApp().m_callSign = val; } - sprintf(reply,"ok\n"); + snprintf(reply, STR_LENGTH, "ok\n"); } if (bufstr.StartsWith(_("ptton"), &itemToSet)) { // note: if options dialog is open this will get overwritten m_btnTogPTT->SetValue(true); togglePTT(); - sprintf(reply,"ok\n"); + snprintf(reply, STR_LENGTH, "ok\n"); } if (bufstr.StartsWith(_("pttoff"), &itemToSet)) { // note: if options dialog is open this will get overwritten m_btnTogPTT->SetValue(false); togglePTT(); - sprintf(reply,"ok\n"); + snprintf(reply, STR_LENGTH, "ok\n"); } } diff --git a/src/ongui.cpp b/src/ongui.cpp index 5c9a2d38..62d477ed 100644 --- a/src/ongui.cpp +++ b/src/ongui.cpp @@ -283,7 +283,7 @@ void MainFrame::OnCmdSliderScroll(wxScrollEvent& event) { char sqsnr[15]; g_SquelchLevel = (float)m_sliderSQ->GetValue()/2.0 - 5.0; - sprintf(sqsnr, "%4.1f dB", g_SquelchLevel); // 0.5 dB steps + snprintf(sqsnr, 15, "%4.1f dB", g_SquelchLevel); // 0.5 dB steps wxString sqsnr_string(sqsnr); m_textSQ->SetLabel(sqsnr_string); @@ -297,7 +297,7 @@ void MainFrame::OnChangeTxLevel( wxScrollEvent& event ) { char fmt[15]; g_txLevel = m_sliderTxLevel->GetValue(); - sprintf(fmt, "%0.1f dB", (double)(g_txLevel)/10.0); + snprintf(fmt, 15, "%0.1f dB", (double)(g_txLevel)/10.0); wxString fmtString(fmt); m_txtTxLevelNum->SetLabel(fmtString); diff --git a/src/plot.cpp b/src/plot.cpp index 1420ed2b..bf160646 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -165,8 +165,10 @@ double PlotPanel::GetZoomFactor(double zf) //------------------------------------------------------------------------- void PlotPanel::drawGraticule(wxGraphicsContext* ctx) { + const int STR_LENGTH = 15; + int p; - char buf[15]; + char buf[STR_LENGTH]; wxString s; wxGraphicsFont tmpFont = ctx->CreateFont(GetFont(), GetForegroundColour()); @@ -188,14 +190,14 @@ void PlotPanel::drawGraticule(wxGraphicsContext* ctx) ctx->SetPen(wxPen(GREY_COLOR, 1)); for(p = GRID_INCREMENT; p < (m_rGrid.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT) { - sprintf(buf, "%1.1f Hz",(double)(p / 10)); + snprintf(buf, STR_LENGTH, "%1.1f Hz",(double)(p / 10)); ctx->DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/2); } // Label the Y-Axis //for(p = GRID_INCREMENT; p < (h - YBOTTOM_OFFSET); p += GRID_INCREMENT) for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) { - sprintf(buf, "%1.0f", (double)((m_rGrid.GetHeight() - p) * -10)); + snprintf(buf, STR_LENGTH, "%1.0f", (double)((m_rGrid.GetHeight() - p) * -10)); ctx->DrawText(buf, XLEFT_TEXT_OFFSET, p); } } diff --git a/src/plot_scalar.cpp b/src/plot_scalar.cpp index c242eca3..092ebc4e 100644 --- a/src/plot_scalar.cpp +++ b/src/plot_scalar.cpp @@ -254,9 +254,11 @@ void PlotScalar::draw(wxGraphicsContext* ctx) //------------------------------------------------------------------------- void PlotScalar::drawGraticule(wxGraphicsContext* ctx) { + const int STR_LENGTH = 15; + float t, a; int x, y, text_w, text_h; - char buf[15]; + char buf[STR_LENGTH]; wxString s; float sec_to_px; float a_to_py; @@ -293,7 +295,7 @@ void PlotScalar::drawGraticule(wxGraphicsContext* ctx) ctx->StrokeLine(x, plotHeight + PLOT_BORDER, x, PLOT_BORDER); } if (!m_mini) { - sprintf(buf, "%2.1fs", t); + snprintf(buf, STR_LENGTH, "%2.1fs", t); GetTextExtent(buf, &text_w, &text_h); ctx->DrawText(buf, x - text_w/2, plotHeight + PLOT_BORDER + YBOTTOM_TEXT_OFFSET); } @@ -319,7 +321,7 @@ void PlotScalar::drawGraticule(wxGraphicsContext* ctx) (plotWidth + PLOT_BORDER + XLEFT_OFFSET), y); } if (!m_mini) { - sprintf(buf, m_a_fmt, a); + snprintf(buf, STR_LENGTH, m_a_fmt, a); GetTextExtent(buf, &text_w, &text_h); ctx->DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2); } diff --git a/src/plot_spectrum.cpp b/src/plot_spectrum.cpp index 48dee51a..d296c322 100644 --- a/src/plot_spectrum.cpp +++ b/src/plot_spectrum.cpp @@ -150,8 +150,10 @@ void PlotSpectrum::draw(wxGraphicsContext* ctx) //------------------------------------------------------------------------- void PlotSpectrum::drawGraticule(wxGraphicsContext* ctx) { + const int STR_LENGTH = 15; + int x, y, text_w, text_h; - char buf[15]; + char buf[STR_LENGTH]; wxString s; float f, mag, freq_hz_to_px, mag_dB_to_py; @@ -175,7 +177,7 @@ void PlotSpectrum::drawGraticule(wxGraphicsContext* ctx) int textXStep = STEP_F_HZ*freq_hz_to_px; int textYStep = STEP_MAG_DB*mag_dB_to_py; - sprintf(buf, "%4.0fHz", (float)MAX_F_HZ - STEP_F_HZ); + snprintf(buf, STR_LENGTH, "%4.0fHz", (float)MAX_F_HZ - STEP_F_HZ); GetTextExtent(buf, &text_w, &text_h); int overlappedText = (text_w > textXStep) || (text_h > textYStep); //printf("text_w: %d textXStep: %d text_h: %d textYStep: %d overlappedText: %d\n", text_w, textXStep, @@ -192,7 +194,7 @@ void PlotSpectrum::drawGraticule(wxGraphicsContext* ctx) ctx->SetPen(wxPen(BLACK_COLOR, 1)); ctx->StrokeLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, m_rGrid.GetHeight() + PLOT_BORDER + YBOTTOM_TEXT_OFFSET); - sprintf(buf, "%4.0fHz", f); + snprintf(buf, STR_LENGTH, "%4.0fHz", f); GetTextExtent(buf, &text_w, &text_h); if (!overlappedText) ctx->DrawText(buf, x - text_w/2, m_rGrid.GetHeight() + PLOT_BORDER + YBOTTOM_TEXT_OFFSET); @@ -214,7 +216,7 @@ void PlotSpectrum::drawGraticule(wxGraphicsContext* ctx) y += PLOT_BORDER; ctx->StrokeLine(PLOT_BORDER + XLEFT_OFFSET, y, (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y); - sprintf(buf, "%3.0fdB", mag); + snprintf(buf, STR_LENGTH, "%3.0fdB", mag); GetTextExtent(buf, &text_w, &text_h); if (!overlappedText) ctx->DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2); diff --git a/src/plot_waterfall.cpp b/src/plot_waterfall.cpp index d7a247a2..8198030d 100644 --- a/src/plot_waterfall.cpp +++ b/src/plot_waterfall.cpp @@ -231,8 +231,10 @@ void PlotWaterfall::draw(wxGraphicsContext* gc) //------------------------------------------------------------------------- void PlotWaterfall::drawGraticule(wxGraphicsContext* ctx) { + const int STR_LENGTH = 15; + int x, y, text_w, text_h; - char buf[15]; + char buf[STR_LENGTH]; wxString s; float f, time, freq_hz_to_px, time_s_to_py; @@ -256,7 +258,7 @@ void PlotWaterfall::drawGraticule(wxGraphicsContext* ctx) int textXStep = STEP_F_HZ*freq_hz_to_px; int textYStep = WATERFALL_SECS_STEP*time_s_to_py; - sprintf(buf, "%4.0fHz", (float)MAX_F_HZ - STEP_F_HZ); + snprintf(buf, STR_LENGTH, "%4.0fHz", (float)MAX_F_HZ - STEP_F_HZ); GetTextExtent(buf, &text_w, &text_h); int overlappedText = (text_w > textXStep) || (text_h > textYStep); @@ -272,7 +274,7 @@ void PlotWaterfall::drawGraticule(wxGraphicsContext* ctx) else ctx->StrokeLine(x, PLOT_BORDER, x, PLOT_BORDER + YBOTTOM_TEXT_OFFSET + 5); - sprintf(buf, "%4.0fHz", f); + snprintf(buf, STR_LENGTH, "%4.0fHz", f); GetTextExtent(buf, &text_w, &text_h); if (!overlappedText) ctx->DrawText(buf, x - text_w/2, (YBOTTOM_TEXT_OFFSET/2)); @@ -294,7 +296,7 @@ void PlotWaterfall::drawGraticule(wxGraphicsContext* ctx) if (m_graticule) ctx->StrokeLine(PLOT_BORDER + XLEFT_OFFSET, y, (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y); - sprintf(buf, "%3.0fs", time); + snprintf(buf, STR_LENGTH, "%3.0fs", time); GetTextExtent(buf, &text_w, &text_h); if (!overlappedText) ctx->DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2); diff --git a/src/util.cpp b/src/util.cpp index 48733a51..23577300 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -256,7 +256,7 @@ void MainFrame::DetectSyncProcessEvent(void) { } if (ds_rx_time >= DS_SYNC_WAIT_TIME) { - char s[100]; sprintf(s, "rx sync"); + char s[100]; snprintf(s, 100, "rx sync"); if (wxGetApp().m_udp_enable) { UDPSend(wxGetApp().m_udp_port, s, strlen(s)+1); }