From 53f02d33a657d4289b06fcff10b9a3b22346fe52 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 20 May 2014 07:05:07 -0700 Subject: [PATCH] Fix a bunch of warnings when building with gcc on linux --- configure.ac | 1 + libaegisub/ass/dialogue_parser.cpp | 2 +- libaegisub/common/file_mapping.cpp | 2 +- libaegisub/common/parser.cpp | 2 +- libaegisub/common/thesaurus.cpp | 2 +- libaegisub/include/libaegisub/thesaurus.h | 2 +- src/audio_provider_pcm.cpp | 4 +++- src/search_replace_engine.cpp | 16 ++++++++-------- src/subtitles_provider.cpp | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 107bc7008..a109ac897 100644 --- a/configure.ac +++ b/configure.ac @@ -151,6 +151,7 @@ AS_IF([test x$enable_compiler_flags != xno], [ CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -pipe -g" AC_CXX_FLAG([-std=c++11]) AC_CXX_FLAG([-Wno-c++11-narrowing]) + AC_C_FLAG([-Wno-unused-local-typedefs]) AC_CXX_FLAG([-Wno-unused-local-typedefs]) # -O* messes with debugging. diff --git a/libaegisub/ass/dialogue_parser.cpp b/libaegisub/ass/dialogue_parser.cpp index 399bf804f..95f4b41e1 100644 --- a/libaegisub/ass/dialogue_parser.cpp +++ b/libaegisub/ass/dialogue_parser.cpp @@ -34,7 +34,7 @@ class SyntaxHighlighter { std::string const& text; agi::SpellChecker *spellchecker; - void SetStyling(int len, int type) { + void SetStyling(size_t len, int type) { if (ranges.size() && ranges.back().type == type) ranges.back().length += len; else diff --git a/libaegisub/common/file_mapping.cpp b/libaegisub/common/file_mapping.cpp index eec8e38ca..5462fff1e 100644 --- a/libaegisub/common/file_mapping.cpp +++ b/libaegisub/common/file_mapping.cpp @@ -121,7 +121,7 @@ file_mapping::~file_mapping() { read_file_mapping::read_file_mapping(fs::path const& filename) : file(filename, false) { - offset_t size; + offset_t size = 0; ipcdetail::get_file_size(file.get_mapping_handle().handle, size); file_size = static_cast(size); } diff --git a/libaegisub/common/parser.cpp b/libaegisub/common/parser.cpp index be59f853d..c855c7e20 100644 --- a/libaegisub/common/parser.cpp +++ b/libaegisub/common/parser.cpp @@ -218,7 +218,7 @@ namespace ass { ptrdiff_t len = it->value().end() - it->value().begin(); assert(len > 0); if (data.empty() || data.back().type != id) - data.push_back(DialogueToken{id, len}); + data.push_back(DialogueToken{id, static_cast(len)}); else data.back().length += len; } diff --git a/libaegisub/common/thesaurus.cpp b/libaegisub/common/thesaurus.cpp index 575e889f5..c26cd3d2b 100644 --- a/libaegisub/common/thesaurus.cpp +++ b/libaegisub/common/thesaurus.cpp @@ -50,7 +50,7 @@ Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_pat std::vector chunks; boost::split(chunks, line, _1 == '|'); if (chunks.size() == 2) - offsets[chunks[0]] = atoi(chunks[1].c_str()); + offsets[chunks[0]] = static_cast(atoi(chunks[1].c_str())); } } diff --git a/libaegisub/include/libaegisub/thesaurus.h b/libaegisub/include/libaegisub/thesaurus.h index 48cf0f653..3630321cf 100644 --- a/libaegisub/include/libaegisub/thesaurus.h +++ b/libaegisub/include/libaegisub/thesaurus.h @@ -31,7 +31,7 @@ namespace charset { class IconvWrapper; } class Thesaurus { /// Map of word -> byte position in the data file - boost::container::flat_map offsets; + boost::container::flat_map offsets; /// Read handle to the data file std::unique_ptr dat; /// Converter from the data file's charset to UTF-8 diff --git a/src/audio_provider_pcm.cpp b/src/audio_provider_pcm.cpp index 54e53b542..e669067c4 100644 --- a/src/audio_provider_pcm.cpp +++ b/src/audio_provider_pcm.cpp @@ -346,7 +346,9 @@ public: throw agi::AudioProviderOpenError("Found 'data' chunk before 'fmt ' chunk, file is invalid.", nullptr); auto samples = chunk_size / bytes_per_sample / channels; - index_points.push_back(IndexPoint{filepos, samples}); + index_points.push_back(IndexPoint{ + static_cast(filepos), + static_cast(samples)}); num_samples += samples; } diff --git a/src/search_replace_engine.cpp b/src/search_replace_engine.cpp index 6d95b15e7..7e3e4bbdf 100644 --- a/src/search_replace_engine.cpp +++ b/src/search_replace_engine.cpp @@ -28,9 +28,10 @@ #include -static const size_t bad_pos = -1; - namespace { +static const size_t bad_pos = -1; +static const MatchState bad_match{nullptr, 0, bad_pos}; + auto get_dialogue_field(SearchReplaceSettings::Field field) -> decltype(&AssDialogueBase::Text) { switch (field) { case SearchReplaceSettings::Field::TEXT: return &AssDialogueBase::Text; @@ -157,7 +158,7 @@ matcher get_matcher(SearchReplaceSettings const& settings, Accessor&& a) { boost::smatch result; auto const& str = a.get(diag, start); if (!u32regex_search(str, result, regex, start > 0 ? boost::match_not_bol : boost::match_default)) - return {nullptr, 0, -1}; + return bad_match; return a.make_match_state(result.position(), result.position() + result.length(), ®ex); }; } @@ -169,19 +170,18 @@ matcher get_matcher(SearchReplaceSettings const& settings, Accessor&& a) { if (!settings.match_case) look_for = boost::locale::fold_case(look_for); - MatchState invalid{nullptr, 0, -1}; return [=](const AssDialogue *diag, size_t start) mutable -> MatchState { const auto str = a.get(diag, start); if (full_match_only && str.size() != look_for.size()) - return invalid; + return bad_match; if (match_case) { const auto pos = str.find(look_for); - return pos == std::string::npos ? invalid : a.make_match_state(pos, pos + look_for.size()); + return pos == std::string::npos ? bad_match : a.make_match_state(pos, pos + look_for.size()); } const auto pos = agi::util::ifind(str, look_for); - return pos.first == bad_pos ? invalid : a.make_match_state(pos.first, pos.second); + return pos.first == bad_pos ? bad_match : a.make_match_state(pos.first, pos.second); }; } @@ -230,7 +230,7 @@ bool SearchReplaceEngine::FindReplace(bool replace) { auto it = context->ass->iterator_to(*line); size_t pos = 0; - MatchState replace_ms{nullptr, 0, -1}; + auto replace_ms = bad_match; if (replace) { if (settings.field == SearchReplaceSettings::Field::TEXT) pos = context->textSelectionController->GetSelectionStart(); diff --git a/src/subtitles_provider.cpp b/src/subtitles_provider.cpp index 0950f7d41..2c19f73a5 100644 --- a/src/subtitles_provider.cpp +++ b/src/subtitles_provider.cpp @@ -89,7 +89,7 @@ void SubtitlesProvider::LoadSubtitles(AssFile *subs, int time) { push_header("[Events]\n"); for (auto const& line : subs->Events) { - if (!line.Comment && time < 0 || !(line.Start > time || line.End <= time)) + if (!line.Comment && (time < 0 || !(line.Start > time || line.End <= time))) push_line(line.GetEntryData()); }