From a0c92f83f96d03d4bb6f2cee171dfbc895b44f17 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 4 Oct 2012 19:10:20 -0700 Subject: [PATCH] Fix some PVS-Studio warnings --- .../include/libaegisub/line_iterator.h | 2 +- aegisub/src/ass_attachment.cpp | 12 ++-- aegisub/src/ass_dialogue.cpp | 57 +++++++++---------- aegisub/src/ass_dialogue.h | 4 +- aegisub/src/ass_exporter.cpp | 2 +- aegisub/src/ass_file.cpp | 16 +++--- aegisub/src/ass_file.h | 8 +-- aegisub/src/ass_override.cpp | 12 ++-- aegisub/src/audio_display.cpp | 4 +- aegisub/src/auto4_lua_assfile.cpp | 4 +- aegisub/src/factory_manager.h | 2 +- 11 files changed, 59 insertions(+), 64 deletions(-) diff --git a/aegisub/libaegisub/include/libaegisub/line_iterator.h b/aegisub/libaegisub/include/libaegisub/line_iterator.h index afee984d6..425f3af97 100644 --- a/aegisub/libaegisub/include/libaegisub/line_iterator.h +++ b/aegisub/libaegisub/include/libaegisub/line_iterator.h @@ -165,7 +165,7 @@ void line_iterator::getline(std::string &str) { u.chr = 0; #if defined(_MSC_VER) && _MSC_VER < 1600 // This _s version is only available in Visual C++ 2005 and 2008, it was removed in VC 2010 - std::streamsize read = stream->rdbuf()->_Sgetn_s(u.buf, 4, width); + std::streamsize read = stream->rdbuf()->_Sgetn_s(u.buf, sizeof(u.buf), width); #else std::streamsize read = stream->rdbuf()->sgetn(u.buf, width); #endif diff --git a/aegisub/src/ass_attachment.cpp b/aegisub/src/ass_attachment.cpp index 591244aba..06514f436 100644 --- a/aegisub/src/ass_attachment.cpp +++ b/aegisub/src/ass_attachment.cpp @@ -67,9 +67,9 @@ AssEntry *AssAttachment::Clone() const { } const wxString AssAttachment::GetEntryData() const { - int pos = 0; - int size = data->size(); - int written = 0; + size_t pos = 0; + size_t size = data->size(); + size_t written = 0; unsigned char src[3]; unsigned char dst[4]; @@ -82,7 +82,7 @@ const wxString AssAttachment::GetEntryData() const { // Read three bytes while (pos < size) { // Number to read - int read = size - pos; + size_t read = size - pos; if (read > 3) read = 3; // Read source @@ -100,10 +100,10 @@ const wxString AssAttachment::GetEntryData() const { dst[3] = src[2] & 0x3F; // Number to write - int toWrite = read+1; + size_t toWrite = read+1; // Convert to text - for (int i=0;i AssDialogue::ParseTags() const { // Look for \p in block std::vector::iterator curTag; - for (curTag = block->Tags.begin();curTag != block->Tags.end();curTag++) { + for (curTag = block->Tags.begin(); curTag != block->Tags.end(); ++curTag) { if ((*curTag)->Name == "\\p") { drawingLevel = (*curTag)->Params[0]->Get(0); } @@ -318,24 +318,25 @@ void AssDialogue::StripTags () { } void AssDialogue::StripTag (wxString tagName) { - using std::list; - using std::vector; ParseASSTags(); wxString final; // Look for blocks - for (vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { - if ((*cur)->GetType() == BLOCK_OVERRIDE) { - AssDialogueBlockOverride *over = dynamic_cast(*cur); - wxString temp; - for (size_t i=0;iTags.size();i++) { - if (over->Tags[i]->Name != tagName) temp += *over->Tags[i]; - } - - // Insert - if (!temp.IsEmpty()) final += "{" + temp + "}"; + for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { + if ((*cur)->GetType() != BLOCK_OVERRIDE) { + final += (*cur)->GetText(); + continue; } - else final += (*cur)->GetText(); + + AssDialogueBlockOverride *over = dynamic_cast(*cur); + wxString temp; + for (size_t i = 0; i < over->Tags.size(); ++i) { + if (over->Tags[i]->Name != tagName) + temp += *over->Tags[i]; + } + + if (!temp.empty()) + final += "{" + temp + "}"; } ClearBlocks(); @@ -345,7 +346,7 @@ void AssDialogue::StripTag (wxString tagName) { void AssDialogue::UpdateText () { if (Blocks.empty()) return; Text.clear(); - for (std::vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { + for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { if ((*cur)->GetType() == BLOCK_OVERRIDE) { Text += "{"; Text += (*cur)->GetText(); @@ -355,16 +356,16 @@ void AssDialogue::UpdateText () { } } -void AssDialogue::SetMarginString(const wxString origvalue,int which) { +void AssDialogue::SetMarginString(wxString const& origvalue, int which) { if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError(); // Make it numeric wxString strvalue = origvalue; if (!strvalue.IsNumber()) { strvalue.clear(); - for (size_t i=0;i= 4) throw Aegisub::InvalidMarginIdError(); - int value = Margin[which]; - if (pad) return wxString::Format("%04i",value); - else return wxString::Format("%i",value); + return wxString::Format(pad ? "%04d" : "%d", Margin[which]); } void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { // Apply for all override blocks - AssDialogueBlockOverride *curBlock; - //ParseASSTags(); - for (std::vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { + for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { if ((*cur)->GetType() == BLOCK_OVERRIDE) { - curBlock = static_cast (*cur); - curBlock->ProcessParameters(callback,userData); + static_cast(*cur)->ProcessParameters(callback, userData); } } - //ClearBlocks(); } bool AssDialogue::CollidesWith(const AssDialogue *target) const { @@ -401,9 +396,9 @@ bool AssDialogue::CollidesWith(const AssDialogue *target) const { } wxString AssDialogue::GetStrippedText() const { - static wxRegEx reg("\\{[^\\{]*\\}",wxRE_ADVANCED); + static const wxRegEx reg("\\{[^\\{]*\\}", wxRE_ADVANCED); wxString txt(Text); - reg.Replace(&txt,""); + reg.Replace(&txt, ""); return txt; } diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index 1bdf00568..64a4ed191 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -178,11 +178,11 @@ public: void SetEntryData(wxString const&) { } template - void SetMarginString(const wxString value) { SetMarginString(value, which);} + void SetMarginString(wxString const& value) { SetMarginString(value, which);} /// @brief Set a margin /// @param value New value of the margin /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom - void SetMarginString(const wxString value,int which); + void SetMarginString(wxString const& value, int which); /// @brief Get a margin /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom /// @param pad Pad the number to four digits diff --git a/aegisub/src/ass_exporter.cpp b/aegisub/src/ass_exporter.cpp index 4c4836194..5b51c5469 100644 --- a/aegisub/src/ass_exporter.cpp +++ b/aegisub/src/ass_exporter.cpp @@ -108,7 +108,7 @@ wxArrayString AssExporter::GetAllFilterNames() const { AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) { AssFile *subs = copy ? new AssFile(*c->ass) : c->ass; - for (filter_iterator cur = filters.begin(); cur != filters.end(); cur++) { + for (filter_iterator cur = filters.begin(); cur != filters.end(); ++cur) { (*cur)->LoadSettings(is_default, c); (*cur)->ProcessSubs(subs, export_dialog); } diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 3c71657a6..d67202f18 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -490,7 +490,7 @@ wxString AssFile::GetScriptInfo(wxString key) const { return ""; } -int AssFile::GetScriptInfoAsInt(const wxString key) const { +int AssFile::GetScriptInfoAsInt(wxString const& key) const { long temp = 0; GetScriptInfo(key).ToLong(&temp); return temp; @@ -585,8 +585,8 @@ wxArrayString AssFile::GetStyles() const { return styles; } -AssStyle *AssFile::GetStyle(wxString name) { - for (entryIter cur=Line.begin();cur!=Line.end();cur++) { +AssStyle *AssFile::GetStyle(wxString const& name) { + for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { AssStyle *curstyle = dynamic_cast(*cur); if (curstyle && curstyle->name == name) return curstyle; @@ -594,7 +594,7 @@ AssStyle *AssFile::GetStyle(wxString name) { return NULL; } -void AssFile::AddToRecent(wxString file) { +void AssFile::AddToRecent(wxString const& file) const { config::mru->Add("Subtitle", STD_STR(file)); wxFileName filepath(file); OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filepath.GetPath())); @@ -602,12 +602,12 @@ void AssFile::AddToRecent(wxString file) { wxString AssFile::GetWildcardList(int mode) { if (mode == 0) return SubtitleFormat::GetWildcards(0); - else if (mode == 1) return "Advanced Substation Alpha (*.ass)|*.ass"; - else if (mode == 2) return SubtitleFormat::GetWildcards(1); - else return ""; + if (mode == 1) return "Advanced Substation Alpha (*.ass)|*.ass"; + if (mode == 2) return SubtitleFormat::GetWildcards(1); + return ""; } -int AssFile::Commit(wxString desc, int type, int amendId, AssEntry *single_line) { +int AssFile::Commit(wxString const& desc, int type, int amendId, AssEntry *single_line) { ++commitId; // Allow coalescing only if it's the last change and the file has not been // saved since the last change diff --git a/aegisub/src/ass_file.h b/aegisub/src/ass_file.h index 709118b17..54e630ee1 100644 --- a/aegisub/src/ass_file.h +++ b/aegisub/src/ass_file.h @@ -119,7 +119,7 @@ public: /// @brief Get a style by name /// @param name Style name /// @return Pointer to style or NULL - AssStyle *GetStyle(wxString name); + AssStyle *GetStyle(wxString const& name); void swap(AssFile &) throw(); @@ -144,7 +144,7 @@ public: /// @param[out] dst Destination vector void SaveMemory(std::vector &dst); /// Add file name to the MRU list - void AddToRecent(wxString file); + void AddToRecent(wxString const& file) const; /// Can the file be saved in its current format? bool CanSave() const; /// @brief Get the list of wildcards supported @@ -156,7 +156,7 @@ public: /// @param[in] h Height void GetResolution(int &w,int &h) const; /// Get the value in a [Script Info] key as int, or 0 if it is not present - int GetScriptInfoAsInt(const wxString key) const; + int GetScriptInfoAsInt(wxString const& key) const; /// Get the value in a [Script Info] key as string. wxString GetScriptInfo(wxString key) const; /// Set the value of a [Script Info] key. Adds it if it doesn't exist. @@ -209,7 +209,7 @@ public: /// @param commitId Commit to amend rather than pushing a new commit /// @param single_line Line which was changed, if only one line was /// @return Unique identifier for the new undo group - int Commit(wxString desc, int type, int commitId = -1, AssEntry *single_line = 0); + int Commit(wxString const& desc, int type, int commitId = -1, AssEntry *single_line = 0); /// @brief Undo the last set of changes to the file void Undo(); /// @brief Redo the last undone changes diff --git a/aegisub/src/ass_override.cpp b/aegisub/src/ass_override.cpp index f2e6a47a5..7e7e0e368 100644 --- a/aegisub/src/ass_override.cpp +++ b/aegisub/src/ass_override.cpp @@ -97,22 +97,22 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) { wxString AssDialogueBlockOverride::GetText() { text.clear(); - for (std::vector::iterator cur=Tags.begin();cur!=Tags.end();cur++) { + for (std::vector::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { text += **cur; } return text; } void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { - for (std::vector::iterator cur=Tags.begin();cur!=Tags.end();cur++) { + for (std::vector::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { AssOverrideTag *curTag = *cur; // Find parameters - for (unsigned n = 0; n < curTag->Params.size(); n++) { + for (size_t n = 0; n < curTag->Params.size(); ++n) { AssOverrideParameter *curPar = curTag->Params[n]; if (curPar->GetType() != VARDATA_NONE && !curPar->omitted) { - (*callback)(curTag->Name,n,curPar,userData); + (*callback)(curTag->Name, n, curPar, userData); // Go recursive if it's a block parameter if (curPar->GetType() == VARDATA_BLOCK) { @@ -291,7 +291,7 @@ void AssOverrideTag::Clear() { void AssOverrideTag::SetText(const wxString &text) { load_protos(); - for (AssOverrideTagProto::iterator cur=proto.begin();cur!=proto.end();cur++) { + for (AssOverrideTagProto::iterator cur = proto.begin(); cur != proto.end(); ++cur) { if (text.StartsWith(cur->name)) { Name = cur->name; ParseParameters(text.Mid(Name.length()), cur); @@ -452,7 +452,7 @@ AssOverrideTag::operator wxString() const { // Add parameters bool any = false; - for (std::vector::const_iterator cur=Params.begin();cur!=Params.end();cur++) { + for (std::vector::const_iterator cur = Params.begin(); cur != Params.end(); ++cur) { if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) { result += (*cur)->Get(); result += ","; diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index 5cc8d4bdf..534cc2d35 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -425,7 +425,7 @@ public: double mark_time = next_scale_mark * scale_minor_divisor / 1000.0; int mark_hour = (int)(mark_time / 3600); int mark_minute = (int)(mark_time / 60) % 60; - double mark_second = mark_time - mark_hour*3600 - mark_minute*60; + double mark_second = mark_time - mark_hour*3600.0 - mark_minute*60.0; wxString time_string; bool changed_hour = mark_hour != last_hour; @@ -677,7 +677,7 @@ void AudioDisplay::SetZoomLevel(int new_zoom_level) if (ms_per_pixel != new_ms_per_pixel) { int client_width = GetClientSize().GetWidth(); - double center_time = (scroll_left + client_width / 2) * ms_per_pixel; + double center_time = (scroll_left + client_width / 2.0) * ms_per_pixel; ms_per_pixel = new_ms_per_pixel; pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel)); diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index 6229b6d75..747b1c929 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -544,8 +544,8 @@ namespace Automation4 { int n = lua_gettop(L); if (last_entry_ptr != lines.begin()) { - last_entry_ptr--; - last_entry_id--; + --last_entry_ptr; + --last_entry_id; } for (int i = 1; i <= n; i++) { diff --git a/aegisub/src/factory_manager.h b/aegisub/src/factory_manager.h index baee71f2b..d8eb77f18 100644 --- a/aegisub/src/factory_manager.h +++ b/aegisub/src/factory_manager.h @@ -83,7 +83,7 @@ public: if (!classes) return list; std::string cmp; std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); - for (iterator cur=classes->begin();cur!=classes->end();cur++) { + for (iterator cur = classes->begin(); cur != classes->end(); ++cur) { cmp.clear(); std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); if (cmp == favourite) list.insert(list.begin(), cur->first);