From 7c730116297b4777e71bc491878ead2f2aa58b2e Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 22:12:23 -0400 Subject: [PATCH 1/6] Where if and else branches were the same, simplify... ... None of the examples was really a bug. ExpandingToolBar.cpp is unused in fact. --- src/widgets/AButton.cpp | 10 +++++----- src/widgets/ASlider.cpp | 6 +++--- src/widgets/ExpandingToolBar.cpp | 6 +++--- src/widgets/Ruler.cpp | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/widgets/AButton.cpp b/src/widgets/AButton.cpp index d21e39100..30510744a 100644 --- a/src/widgets/AButton.cpp +++ b/src/widgets/AButton.cpp @@ -299,12 +299,12 @@ AButton::AButtonState AButton::GetState() } } else { - if (mToggle) { + //if (mToggle) { state = mButtonIsDown ? AButtonDown : AButtonUp; - } - else { - state = mButtonIsDown ? AButtonDown : AButtonUp; - } + //} + //else { + //state = mButtonIsDown ? AButtonDown : AButtonUp; + //} } return state; diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 7814098db..071b624c2 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -391,10 +391,10 @@ LWSlider::LWSlider(wxWindow *parent, break; case DB_SLIDER: minValue = -36.0f; - if (orientation == wxHORIZONTAL) + //if (orientation == wxHORIZONTAL) maxValue = 36.0f; - else - maxValue = 36.0f; // for MixerBoard //v Previously was 6dB for MixerBoard, but identical for now. + //else + //maxValue = 36.0f; // for MixerBoard //v Previously was 6dB for MixerBoard, but identical for now. stepValue = 1.0f; speed = 0.5; break; diff --git a/src/widgets/ExpandingToolBar.cpp b/src/widgets/ExpandingToolBar.cpp index b175d7a3a..d6f6674c9 100644 --- a/src/widgets/ExpandingToolBar.cpp +++ b/src/widgets/ExpandingToolBar.cpp @@ -291,10 +291,10 @@ class ExpandingToolBarEvtHandler final : public wxEvtHandler bool ProcessEvent(wxEvent& evt) override { - if (mToolBar->IsCursorInWindow()) - mToolBar->TryAutoExpand(); - else +// if (mToolBar->IsCursorInWindow()) mToolBar->TryAutoExpand(); +// else +// mToolBar->TryAutoExpand(); return mInheritedEvtHandler->ProcessEvent(evt); } diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index e6f5f23e4..d84223648 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2427,10 +2427,10 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) // Do this hack so scrubber can detect mouse drags anywhere evt.ResumePropagation(wxEVENT_PROPAGATE_MAX); - if (scrubber.IsScrubbing()) - evt.Skip(); - else + //if (scrubber.IsScrubbing()) evt.Skip(); + //else + //evt.Skip(); // Don't do this, it slows down drag-scrub on Mac. // Timer updates of display elsewhere make it unnecessary. From 168db87ddfb178fe319f3ca679d465f20fff538b Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 22:19:29 -0400 Subject: [PATCH 2/6] Fix identical sub-expressions of - operator --- src/VoiceKey.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/VoiceKey.cpp b/src/VoiceKey.cpp index 9876bf7f6..b1c39c6d1 100644 --- a/src/VoiceKey.cpp +++ b/src/VoiceKey.cpp @@ -306,8 +306,15 @@ sampleCount VoiceKey::OnBackward ( //Initialize these trend markers atrend and ztrend. They keep track of the //up/down trends at the start and end of the evaluation window. int atrend = sgn(buffer[remaining - 2]-buffer[remaining - 1]); + int ztrend = sgn(buffer[remaining - WindowSizeInt - 2] - - buffer[remaining - WindowSizeInt - 2]); + buffer[remaining - WindowSizeInt + // PVS-Studio detected a probable error here + // when it read - 2. + // is - 1 correct? + // This code is unused. I didn't study further. + - 1 + ]); double erg=0; double sc = 0; From 4644b5cb16d1be6a765092386a2db8f96c5b6bee Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 22:32:31 -0400 Subject: [PATCH 3/6] Simplify condition --- src/prefs/ExtImportPrefs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/prefs/ExtImportPrefs.cpp b/src/prefs/ExtImportPrefs.cpp index 80bede526..324c1e2cc 100644 --- a/src/prefs/ExtImportPrefs.cpp +++ b/src/prefs/ExtImportPrefs.cpp @@ -602,7 +602,8 @@ void ExtImportPrefs::OnDelRule(wxCommandEvent& WXUNUSED(event)) int msgres = AudacityMessageBox (_("Do you really want to delete selected rule?"), _("Rule deletion confirmation"), wxYES_NO, RuleTable); - if (msgres == wxNO || msgres != wxYES) + // Yes or no, there is no third! + if (msgres != wxYES) return; RuleTable->DeleteRows (last_selected); From c40b254626f76689e257c2e3f0a23fbb78bd3402 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 22:38:42 -0400 Subject: [PATCH 4/6] while -> if --- src/effects/Equalization.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 732e0a3c7..b5e703baf 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -369,8 +369,11 @@ bool EffectEqualization::ValidateUI() { // If editing a batch chain, we don't want to be using the unnamed curve so // we offer to save it. - while (mDisallowCustom && mCurveName.IsSameAs(wxT("unnamed"))) + + if (mDisallowCustom && mCurveName.IsSameAs(wxT("unnamed"))) { + // PRL: This is unreachable. mDisallowCustom is always false. + Effect::MessageBox(_("To use this EQ curve in a batch chain, please choose a new name for it.\nChoose the 'Save/Manage Curves...' button and rename the 'unnamed' curve, then use that one."), wxOK | wxCENTRE, _("EQ Curve needs a different name")); From 0a035b0ffc66c96d5bb768157a5f501b01bbcdf2 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 23:02:10 -0400 Subject: [PATCH 5/6] Avoid bit-shifting of -1 value --- src/export/ExportFFmpeg.cpp | 2 +- src/export/ExportFFmpegDialogs.cpp | 4 ++-- src/export/ExportFFmpegDialogs.h | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/export/ExportFFmpeg.cpp b/src/export/ExportFFmpeg.cpp index 65a208da3..0e81fc4c3 100644 --- a/src/export/ExportFFmpeg.cpp +++ b/src/export/ExportFFmpeg.cpp @@ -227,7 +227,7 @@ ExportFFmpeg::ExportFFmpeg() SetDescription(ExportFFmpegOptions::fmts[newfmt].Description(), fmtindex); int canmeta = ExportFFmpegOptions::fmts[newfmt].canmetadata; - if (canmeta && (canmeta == AV_VERSION_INT(-1,-1,-1) || canmeta <= avfver)) + if (canmeta && (canmeta == AV_CANMETA || canmeta <= avfver)) { SetCanMetaData(true,fmtindex); } diff --git a/src/export/ExportFFmpegDialogs.cpp b/src/export/ExportFFmpegDialogs.cpp index 00bb0f850..16f64ee81 100644 --- a/src/export/ExportFFmpegDialogs.cpp +++ b/src/export/ExportFFmpegDialogs.cpp @@ -1218,11 +1218,11 @@ static wxString iAACProfileNames(int index) /// List of export types ExposedFormat ExportFFmpegOptions::fmts[] = { - {FMT_M4A, wxT("M4A"), wxT("m4a"), wxT("ipod"), 48, AV_VERSION_INT(-1,-1,-1), true, XO("M4A (AAC) Files (FFmpeg)"), AV_CODEC_ID_AAC, true}, + {FMT_M4A, wxT("M4A"), wxT("m4a"), wxT("ipod"), 48, AV_CANMETA, true, XO("M4A (AAC) Files (FFmpeg)"), AV_CODEC_ID_AAC, true}, {FMT_AC3, wxT("AC3"), wxT("ac3"), wxT("ac3"), 7, AV_VERSION_INT(0,0,0), false, XO("AC3 Files (FFmpeg)"), AV_CODEC_ID_AC3, true}, {FMT_AMRNB, wxT("AMRNB"), wxT("amr"), wxT("amr"), 1, AV_VERSION_INT(0,0,0), false, XO("AMR (narrow band) Files (FFmpeg)"), AV_CODEC_ID_AMR_NB, true}, {FMT_WMA2, wxT("WMA"), wxT("wma"), wxT("asf"), 2, AV_VERSION_INT(52,53,0), false, XO("WMA (version 2) Files (FFmpeg)"), AV_CODEC_ID_WMAV2, true}, - {FMT_OTHER, wxT("FFMPEG"), wxT(""), wxT(""), 255, AV_VERSION_INT(-1,-1,-1), true, XO("Custom FFmpeg Export"), AV_CODEC_ID_NONE, true} + {FMT_OTHER, wxT("FFMPEG"), wxT(""), wxT(""), 255, AV_CANMETA, true, XO("Custom FFmpeg Export"), AV_CODEC_ID_NONE, true} }; wxString ExposedFormat::Description() const diff --git a/src/export/ExportFFmpegDialogs.h b/src/export/ExportFFmpegDialogs.h index 0f02b0196..252191dbe 100644 --- a/src/export/ExportFFmpegDialogs.h +++ b/src/export/ExportFFmpegDialogs.h @@ -38,6 +38,8 @@ enum FFmpegExposedFormat FMT_LAST }; +#define AV_CANMETA (AV_VERSION_INT(255, 255, 255)) + /// Describes export type struct ExposedFormat { @@ -46,7 +48,7 @@ struct ExposedFormat const wxChar *extension; //!< default extension for this format. More extensions may be added later via AddExtension. const wxChar *shortname; //!< used to guess the format unsigned maxchannels; //!< how many channels this format could handle - int canmetadata; //!< !=0 if format supports metadata, -1 any avformat version, otherwise version support added + const int canmetadata; //!< !=0 if format supports metadata, AV_CANMETA any avformat version, otherwise version support added bool canutf8; //!< true if format supports metadata in UTF-8, false otherwise const wxChar *description_; //!< format description (will be shown in export dialog) (untranslated!) AVCodecID codecid; //!< codec ID (see libavcodec/avcodec.h) From ec31d105bf74cb7020b257c62fed88330cbd6c6d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 11 Oct 2017 23:16:21 -0400 Subject: [PATCH 6/6] Simplify conditions --- src/effects/vamp/LoadVamp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/effects/vamp/LoadVamp.cpp b/src/effects/vamp/LoadVamp.cpp index 2956b6692..9ff7d8bf7 100644 --- a/src/effects/vamp/LoadVamp.cpp +++ b/src/effects/vamp/LoadVamp.cpp @@ -166,7 +166,7 @@ wxArrayString VampEffectsModule::FindPluginPaths(PluginManagerInterface & WXUNUS if (j->sampleType == Plugin::OutputDescriptor::FixedSampleRate || j->sampleType == Plugin::OutputDescriptor::OneSamplePerStep || !j->hasFixedBinCount || - (j->hasFixedBinCount && j->binCount > 1)) + j->binCount > 1) { // All of these qualities disqualify (see notes above) @@ -299,7 +299,7 @@ std::unique_ptr VampEffectsModule::FindPlugin(const wxString & pat if (j->sampleType == Plugin::OutputDescriptor::FixedSampleRate || j->sampleType == Plugin::OutputDescriptor::OneSamplePerStep || !j->hasFixedBinCount || - (j->hasFixedBinCount && j->binCount > 1)) + j->binCount > 1) { // All of these qualities disqualify (see notes above)