mirror of https://github.com/odrling/Aegisub
Fix some PVS-Studio warnings
This commit is contained in:
parent
189615bf48
commit
a0c92f83f9
|
@ -165,7 +165,7 @@ void line_iterator<OutputType>::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
|
||||
|
|
|
@ -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<toWrite;i++) {
|
||||
for (size_t i=0;i<toWrite;i++) {
|
||||
entryData += dst[i]+33;
|
||||
written++;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ AssDialogue::AssDialogue()
|
|||
, End(5000)
|
||||
, Style("Default")
|
||||
{
|
||||
for (int i=0;i<4;i++) Margin[i] = 0;
|
||||
memset(Margin, 0, sizeof Margin);
|
||||
}
|
||||
|
||||
AssDialogue::AssDialogue(AssDialogue const& that)
|
||||
|
@ -274,7 +274,7 @@ std::vector<AssDialogueBlock*> AssDialogue::ParseTags() const {
|
|||
|
||||
// Look for \p in block
|
||||
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") {
|
||||
drawingLevel = (*curTag)->Params[0]->Get<int>(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<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
|
||||
if ((*cur)->GetType() == BLOCK_OVERRIDE) {
|
||||
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];
|
||||
}
|
||||
|
||||
// Insert
|
||||
if (!temp.IsEmpty()) final += "{" + temp + "}";
|
||||
for (std::vector<AssDialogueBlock*>::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<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();
|
||||
|
@ -345,7 +346,7 @@ void AssDialogue::StripTag (wxString tagName) {
|
|||
void AssDialogue::UpdateText () {
|
||||
if (Blocks.empty()) return;
|
||||
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) {
|
||||
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<origvalue.Length();i++) {
|
||||
if (origvalue.Mid(i,1).IsNumber()) {
|
||||
strvalue += origvalue.Mid(i,1);
|
||||
for (size_t i = 0; i < origvalue.Length(); ++i) {
|
||||
if (origvalue.Mid(i, 1).IsNumber()) {
|
||||
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 {
|
||||
if (which < 0 || which >= 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<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) {
|
||||
curBlock = static_cast<AssDialogueBlockOverride*> (*cur);
|
||||
curBlock->ProcessParameters(callback,userData);
|
||||
static_cast<AssDialogueBlockOverride*>(*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;
|
||||
}
|
||||
|
||||
|
|
|
@ -178,11 +178,11 @@ public:
|
|||
void SetEntryData(wxString const&) { }
|
||||
|
||||
template<int which>
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<AssStyle*>(*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
|
||||
|
|
|
@ -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<char> &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
|
||||
|
|
|
@ -97,22 +97,22 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) {
|
|||
|
||||
wxString AssDialogueBlockOverride::GetText() {
|
||||
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;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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<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) {
|
||||
result += (*cur)->Get<wxString>();
|
||||
result += ",";
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue