From be4d37dac3b6c55648506f1968c4b7c56ff5722d Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Wed, 31 Jan 2018 06:55:53 +0100 Subject: [PATCH] Fix integer sign comparison --- src/include_complete.cc | 2 +- src/language_server_api.cc | 2 +- src/lex_utils.cc | 6 +++--- src/lru_cache.h | 2 +- src/messages/text_document_code_action.cc | 2 +- src/messages/text_document_completion.cc | 4 ++-- src/messages/workspace_symbol.cc | 2 +- src/project.cc | 10 +++++----- src/test.cc | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/include_complete.cc b/src/include_complete.cc index 9ebed83a..cadc2fd3 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -20,7 +20,7 @@ std::string ElideLongPath(Config* config, const std::string& path) { if (config->includeCompletionMaximumPathLength <= 0) return path; - if (path.size() <= config->includeCompletionMaximumPathLength) + if ((int)path.size() <= config->includeCompletionMaximumPathLength) return path; size_t start = path.size() - config->includeCompletionMaximumPathLength; diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 0f4898c5..5bbb5914 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -57,7 +57,7 @@ optional ReadJsonRpcContentFrom( // Read content. std::string content; content.reserve(content_length); - for (size_t i = 0; i < content_length; ++i) { + for (int i = 0; i < content_length; ++i) { optional c = read(); if (!c) { LOG_S(INFO) << "No more input when reading content body"; diff --git a/src/lex_utils.cc b/src/lex_utils.cc index 60a76c37..db719c88 100644 --- a/src/lex_utils.cc +++ b/src/lex_utils.cc @@ -27,7 +27,7 @@ lsPosition CharPos(std::string_view search, char character, int character_offset) { lsPosition result; - int index = 0; + size_t index = 0; while (index < search.size()) { char c = search[index]; if (c == character) @@ -91,13 +91,13 @@ void DecorateIncludePaths(const std::smatch& match, optional ExtractQuotedRange(int line_number, const std::string& line) { // Find starting and ending quote. int start = 0; - while (start < line.size()) { + while (start < (int)line.size()) { char c = line[start]; ++start; if (c == '"' || c == '<') break; } - if (start == line.size()) + if (start == (int)line.size()) return nullopt; int end = (int)line.size(); diff --git a/src/lru_cache.h b/src/lru_cache.h index c3e065d7..5539cc78 100644 --- a/src/lru_cache.h +++ b/src/lru_cache.h @@ -95,7 +95,7 @@ std::shared_ptr LruCache::TryTake(const TKey& key) { template void LruCache::Insert(const TKey& key, const std::shared_ptr& value) { - if (entries_.size() >= max_entries_) + if ((int)entries_.size() >= max_entries_) entries_.erase(std::min_element(entries_.begin(), entries_.end())); Entry entry; diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc index 79bde007..a9d597ae 100644 --- a/src/messages/text_document_code_action.cc +++ b/src/messages/text_document_code_action.cc @@ -456,7 +456,7 @@ struct TextDocumentCodeActionHandler std::unordered_set include_absolute_paths; // Find include candidate strings. - for (int i = 0; i < db->symbols.size(); ++i) { + for (size_t i = 0; i < db->symbols.size(); ++i) { if (include_absolute_paths.size() > kMaxResults) break; if (db->GetSymbolDetailedName(i).find(include_query) == diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index e2f25820..d62cb4fe 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -221,7 +221,7 @@ struct TextDocumentCompletionHandler : MessageHandler { bool did_fail_check = false; std::string character = *request->params.context->triggerCharacter; - char preceding_index = request->params.position.character - 2; + int preceding_index = request->params.position.character - 2; // If the character is '"', '<' or '/', make sure that the line starts with '#'. if (character == "\"" || character == "<" || character == "/") { @@ -238,7 +238,7 @@ struct TextDocumentCompletionHandler : MessageHandler { } // If the character is > but - does not preced it, or if it is : and : // does not preced it, do not show completion results. - else if (preceding_index < buffer_line.size()) { + else if (preceding_index < (int)buffer_line.size()) { char preceding = buffer_line[preceding_index]; did_fail_check = (preceding != '-' && character == ">") || (preceding != ':' && character == ":"); diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index a78ca994..5fcfec5d 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -106,7 +106,7 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { if (!isspace(c)) query_without_space += c; - for (int i = 0; i < db->symbols.size(); ++i) { + for (int i = 0; i < (int)db->symbols.size(); ++i) { std::string_view detailed_name = db->GetSymbolDetailedName(i); if (SubsequenceMatch(query_without_space, detailed_name)) { // Do not show the same entry twice. diff --git a/src/project.cc b/src/project.cc index e5e0a35f..4b742def 100644 --- a/src/project.cc +++ b/src/project.cc @@ -428,28 +428,28 @@ int ComputeGuessScore(const std::string& a, const std::string& b) { const int kMatchPostfixWeight = 1; int score = 0; - int i = 0; + size_t i = 0; // Increase score based on matching prefix. - for (i = 0; i < a.length() && i < b.length(); ++i) { + for (i = 0; i < a.size() && i < b.size(); ++i) { if (a[i] != b[i]) break; score += kMatchPrefixWeight; } // Reduce score based on mismatched directory distance. - for (int j = i; j < a.length(); ++j) { + for (size_t j = i; j < a.size(); ++j) { if (a[j] == '/') score -= kMismatchDirectoryWeight; } - for (int j = i; j < b.length(); ++j) { + for (size_t j = i; j < b.size(); ++j) { if (b[j] == '/') score -= kMismatchDirectoryWeight; } // Increase score based on common ending. Don't increase as much as matching // prefix or directory distance. - for (int offset = 1; offset <= a.length() && offset <= b.length(); ++offset) { + for (size_t offset = 1; offset <= a.size() && offset <= b.size(); ++offset) { if (a[a.size() - offset] != b[b.size() - offset]) break; score += kMatchPostfixWeight; diff --git a/src/test.cc b/src/test.cc index 649af204..b1d2680f 100644 --- a/src/test.cc +++ b/src/test.cc @@ -81,7 +81,7 @@ void DiffDocuments(std::string path, int max_diff = 5; size_t len = std::min(actual_output.size(), expected_output.size()); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (actual_output[i] != expected_output[i]) { if (--max_diff < 0) { std::cout << "(... more lines may differ ...)" << std::endl;