Fix some PVS-Studio warnings

This commit is contained in:
Thomas Goyne 2012-10-04 19:10:20 -07:00
parent 189615bf48
commit a0c92f83f9
11 changed files with 59 additions and 64 deletions

View file

@ -165,7 +165,7 @@ void line_iterator<OutputType>::getline(std::string &str) {
u.chr = 0; u.chr = 0;
#if defined(_MSC_VER) && _MSC_VER < 1600 #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 // 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 #else
std::streamsize read = stream->rdbuf()->sgetn(u.buf, width); std::streamsize read = stream->rdbuf()->sgetn(u.buf, width);
#endif #endif

View file

@ -67,9 +67,9 @@ AssEntry *AssAttachment::Clone() const {
} }
const wxString AssAttachment::GetEntryData() const { const wxString AssAttachment::GetEntryData() const {
int pos = 0; size_t pos = 0;
int size = data->size(); size_t size = data->size();
int written = 0; size_t written = 0;
unsigned char src[3]; unsigned char src[3];
unsigned char dst[4]; unsigned char dst[4];
@ -82,7 +82,7 @@ const wxString AssAttachment::GetEntryData() const {
// Read three bytes // Read three bytes
while (pos < size) { while (pos < size) {
// Number to read // Number to read
int read = size - pos; size_t read = size - pos;
if (read > 3) read = 3; if (read > 3) read = 3;
// Read source // Read source
@ -100,10 +100,10 @@ const wxString AssAttachment::GetEntryData() const {
dst[3] = src[2] & 0x3F; dst[3] = src[2] & 0x3F;
// Number to write // Number to write
int toWrite = read+1; size_t toWrite = read+1;
// Convert to text // Convert to text
for (int i=0;i<toWrite;i++) { for (size_t i=0;i<toWrite;i++) {
entryData += dst[i]+33; entryData += dst[i]+33;
written++; written++;

View file

@ -56,7 +56,7 @@ AssDialogue::AssDialogue()
, End(5000) , End(5000)
, Style("Default") , Style("Default")
{ {
for (int i=0;i<4;i++) Margin[i] = 0; memset(Margin, 0, sizeof Margin);
} }
AssDialogue::AssDialogue(AssDialogue const& that) AssDialogue::AssDialogue(AssDialogue const& that)
@ -274,7 +274,7 @@ std::vector<AssDialogueBlock*> AssDialogue::ParseTags() const {
// Look for \p in block // Look for \p in block
std::vector<AssOverrideTag*>::iterator curTag; std::vector<AssOverrideTag*>::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") { if ((*curTag)->Name == "\\p") {
drawingLevel = (*curTag)->Params[0]->Get<int>(0); drawingLevel = (*curTag)->Params[0]->Get<int>(0);
} }
@ -318,24 +318,25 @@ void AssDialogue::StripTags () {
} }
void AssDialogue::StripTag (wxString tagName) { void AssDialogue::StripTag (wxString tagName) {
using std::list;
using std::vector;
ParseASSTags(); ParseASSTags();
wxString final; wxString final;
// Look for blocks // Look for blocks
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) {
if ((*cur)->GetType() == BLOCK_OVERRIDE) { if ((*cur)->GetType() != BLOCK_OVERRIDE) {
AssDialogueBlockOverride *over = dynamic_cast<AssDialogueBlockOverride*>(*cur); final += (*cur)->GetText();
wxString temp; continue;
for (size_t i=0;i<over->Tags.size();i++) {
if (over->Tags[i]->Name != tagName) temp += *over->Tags[i];
}
// Insert
if (!temp.IsEmpty()) final += "{" + temp + "}";
} }
else final += (*cur)->GetText();
AssDialogueBlockOverride *over = dynamic_cast<AssDialogueBlockOverride*>(*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(); ClearBlocks();
@ -345,7 +346,7 @@ void AssDialogue::StripTag (wxString tagName) {
void AssDialogue::UpdateText () { void AssDialogue::UpdateText () {
if (Blocks.empty()) return; if (Blocks.empty()) return;
Text.clear(); Text.clear();
for (std::vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) {
if ((*cur)->GetType() == BLOCK_OVERRIDE) { if ((*cur)->GetType() == BLOCK_OVERRIDE) {
Text += "{"; Text += "{";
Text += (*cur)->GetText(); 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(); if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError();
// Make it numeric // Make it numeric
wxString strvalue = origvalue; wxString strvalue = origvalue;
if (!strvalue.IsNumber()) { if (!strvalue.IsNumber()) {
strvalue.clear(); strvalue.clear();
for (size_t i=0;i<origvalue.Length();i++) { for (size_t i = 0; i < origvalue.Length(); ++i) {
if (origvalue.Mid(i,1).IsNumber()) { if (origvalue.Mid(i, 1).IsNumber()) {
strvalue += origvalue.Mid(i,1); strvalue += origvalue.Mid(i, 1);
} }
} }
} }
@ -377,22 +378,16 @@ void AssDialogue::SetMarginString(const wxString origvalue,int which) {
wxString AssDialogue::GetMarginString(int which,bool pad) const { wxString AssDialogue::GetMarginString(int which,bool pad) const {
if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError(); if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError();
int value = Margin[which]; return wxString::Format(pad ? "%04d" : "%d", Margin[which]);
if (pad) return wxString::Format("%04i",value);
else return wxString::Format("%i",value);
} }
void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
// Apply for all override blocks // Apply for all override blocks
AssDialogueBlockOverride *curBlock; for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) {
//ParseASSTags();
for (std::vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
if ((*cur)->GetType() == BLOCK_OVERRIDE) { if ((*cur)->GetType() == BLOCK_OVERRIDE) {
curBlock = static_cast<AssDialogueBlockOverride*> (*cur); static_cast<AssDialogueBlockOverride*>(*cur)->ProcessParameters(callback, userData);
curBlock->ProcessParameters(callback,userData);
} }
} }
//ClearBlocks();
} }
bool AssDialogue::CollidesWith(const AssDialogue *target) const { bool AssDialogue::CollidesWith(const AssDialogue *target) const {
@ -401,9 +396,9 @@ bool AssDialogue::CollidesWith(const AssDialogue *target) const {
} }
wxString AssDialogue::GetStrippedText() const { wxString AssDialogue::GetStrippedText() const {
static wxRegEx reg("\\{[^\\{]*\\}",wxRE_ADVANCED); static const wxRegEx reg("\\{[^\\{]*\\}", wxRE_ADVANCED);
wxString txt(Text); wxString txt(Text);
reg.Replace(&txt,""); reg.Replace(&txt, "");
return txt; return txt;
} }

View file

@ -178,11 +178,11 @@ public:
void SetEntryData(wxString const&) { } void SetEntryData(wxString const&) { }
template<int which> template<int which>
void SetMarginString(const wxString value) { SetMarginString(value, which);} void SetMarginString(wxString const& value) { SetMarginString(value, which);}
/// @brief Set a margin /// @brief Set a margin
/// @param value New value of the margin /// @param value New value of the margin
/// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom /// @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 /// @brief Get a margin
/// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom
/// @param pad Pad the number to four digits /// @param pad Pad the number to four digits

View file

@ -108,7 +108,7 @@ wxArrayString AssExporter::GetAllFilterNames() const {
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) { AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) {
AssFile *subs = copy ? new AssFile(*c->ass) : c->ass; 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)->LoadSettings(is_default, c);
(*cur)->ProcessSubs(subs, export_dialog); (*cur)->ProcessSubs(subs, export_dialog);
} }

View file

@ -490,7 +490,7 @@ wxString AssFile::GetScriptInfo(wxString key) const {
return ""; return "";
} }
int AssFile::GetScriptInfoAsInt(const wxString key) const { int AssFile::GetScriptInfoAsInt(wxString const& key) const {
long temp = 0; long temp = 0;
GetScriptInfo(key).ToLong(&temp); GetScriptInfo(key).ToLong(&temp);
return temp; return temp;
@ -585,8 +585,8 @@ wxArrayString AssFile::GetStyles() const {
return styles; return styles;
} }
AssStyle *AssFile::GetStyle(wxString name) { AssStyle *AssFile::GetStyle(wxString const& name) {
for (entryIter cur=Line.begin();cur!=Line.end();cur++) { for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) {
AssStyle *curstyle = dynamic_cast<AssStyle*>(*cur); AssStyle *curstyle = dynamic_cast<AssStyle*>(*cur);
if (curstyle && curstyle->name == name) if (curstyle && curstyle->name == name)
return curstyle; return curstyle;
@ -594,7 +594,7 @@ AssStyle *AssFile::GetStyle(wxString name) {
return NULL; return NULL;
} }
void AssFile::AddToRecent(wxString file) { void AssFile::AddToRecent(wxString const& file) const {
config::mru->Add("Subtitle", STD_STR(file)); config::mru->Add("Subtitle", STD_STR(file));
wxFileName filepath(file); wxFileName filepath(file);
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filepath.GetPath())); OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filepath.GetPath()));
@ -602,12 +602,12 @@ void AssFile::AddToRecent(wxString file) {
wxString AssFile::GetWildcardList(int mode) { wxString AssFile::GetWildcardList(int mode) {
if (mode == 0) return SubtitleFormat::GetWildcards(0); if (mode == 0) return SubtitleFormat::GetWildcards(0);
else if (mode == 1) return "Advanced Substation Alpha (*.ass)|*.ass"; if (mode == 1) return "Advanced Substation Alpha (*.ass)|*.ass";
else if (mode == 2) return SubtitleFormat::GetWildcards(1); if (mode == 2) return SubtitleFormat::GetWildcards(1);
else return ""; 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; ++commitId;
// Allow coalescing only if it's the last change and the file has not been // Allow coalescing only if it's the last change and the file has not been
// saved since the last change // saved since the last change

View file

@ -119,7 +119,7 @@ public:
/// @brief Get a style by name /// @brief Get a style by name
/// @param name Style name /// @param name Style name
/// @return Pointer to style or NULL /// @return Pointer to style or NULL
AssStyle *GetStyle(wxString name); AssStyle *GetStyle(wxString const& name);
void swap(AssFile &) throw(); void swap(AssFile &) throw();
@ -144,7 +144,7 @@ public:
/// @param[out] dst Destination vector /// @param[out] dst Destination vector
void SaveMemory(std::vector<char> &dst); void SaveMemory(std::vector<char> &dst);
/// Add file name to the MRU list /// 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? /// Can the file be saved in its current format?
bool CanSave() const; bool CanSave() const;
/// @brief Get the list of wildcards supported /// @brief Get the list of wildcards supported
@ -156,7 +156,7 @@ public:
/// @param[in] h Height /// @param[in] h Height
void GetResolution(int &w,int &h) const; void GetResolution(int &w,int &h) const;
/// Get the value in a [Script Info] key as int, or 0 if it is not present /// 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. /// Get the value in a [Script Info] key as string.
wxString GetScriptInfo(wxString key) const; wxString GetScriptInfo(wxString key) const;
/// Set the value of a [Script Info] key. Adds it if it doesn't exist. /// 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 commitId Commit to amend rather than pushing a new commit
/// @param single_line Line which was changed, if only one line was /// @param single_line Line which was changed, if only one line was
/// @return Unique identifier for the new undo group /// @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 /// @brief Undo the last set of changes to the file
void Undo(); void Undo();
/// @brief Redo the last undone changes /// @brief Redo the last undone changes

View file

@ -97,22 +97,22 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) {
wxString AssDialogueBlockOverride::GetText() { wxString AssDialogueBlockOverride::GetText() {
text.clear(); text.clear();
for (std::vector<AssOverrideTag*>::iterator cur=Tags.begin();cur!=Tags.end();cur++) { for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) {
text += **cur; text += **cur;
} }
return text; return text;
} }
void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
for (std::vector<AssOverrideTag*>::iterator cur=Tags.begin();cur!=Tags.end();cur++) { for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) {
AssOverrideTag *curTag = *cur; AssOverrideTag *curTag = *cur;
// Find parameters // 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]; AssOverrideParameter *curPar = curTag->Params[n];
if (curPar->GetType() != VARDATA_NONE && !curPar->omitted) { 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 // Go recursive if it's a block parameter
if (curPar->GetType() == VARDATA_BLOCK) { if (curPar->GetType() == VARDATA_BLOCK) {
@ -291,7 +291,7 @@ void AssOverrideTag::Clear() {
void AssOverrideTag::SetText(const wxString &text) { void AssOverrideTag::SetText(const wxString &text) {
load_protos(); 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)) { if (text.StartsWith(cur->name)) {
Name = cur->name; Name = cur->name;
ParseParameters(text.Mid(Name.length()), cur); ParseParameters(text.Mid(Name.length()), cur);
@ -452,7 +452,7 @@ AssOverrideTag::operator wxString() const {
// Add parameters // Add parameters
bool any = false; bool any = false;
for (std::vector<AssOverrideParameter*>::const_iterator cur=Params.begin();cur!=Params.end();cur++) { for (std::vector<AssOverrideParameter*>::const_iterator cur = Params.begin(); cur != Params.end(); ++cur) {
if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) { if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) {
result += (*cur)->Get<wxString>(); result += (*cur)->Get<wxString>();
result += ","; result += ",";

View file

@ -425,7 +425,7 @@ public:
double mark_time = next_scale_mark * scale_minor_divisor / 1000.0; double mark_time = next_scale_mark * scale_minor_divisor / 1000.0;
int mark_hour = (int)(mark_time / 3600); int mark_hour = (int)(mark_time / 3600);
int mark_minute = (int)(mark_time / 60) % 60; 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; wxString time_string;
bool changed_hour = mark_hour != last_hour; 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) if (ms_per_pixel != new_ms_per_pixel)
{ {
int client_width = GetClientSize().GetWidth(); 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; ms_per_pixel = new_ms_per_pixel;
pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel)); pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));

View file

@ -544,8 +544,8 @@ namespace Automation4 {
int n = lua_gettop(L); int n = lua_gettop(L);
if (last_entry_ptr != lines.begin()) { if (last_entry_ptr != lines.begin()) {
last_entry_ptr--; --last_entry_ptr;
last_entry_id--; --last_entry_id;
} }
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {

View file

@ -83,7 +83,7 @@ public:
if (!classes) return list; if (!classes) return list;
std::string cmp; std::string cmp;
std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); 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(); cmp.clear();
std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower);
if (cmp == favourite) list.insert(list.begin(), cur->first); if (cmp == favourite) list.insert(list.begin(), cur->first);