From 4addd80a5c9b8c0d36d35b0e5e92eb877abf2304 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 31 May 2011 01:15:11 +0200 Subject: [PATCH] Fixed VS runtime error with empty &vector[0] --- search/keyword_matcher.cpp | 2 +- search/keyword_matcher.hpp | 4 ++-- search/query.cpp | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/search/keyword_matcher.cpp b/search/keyword_matcher.cpp index 37e0be3fc0..6a3840646c 100644 --- a/search/keyword_matcher.cpp +++ b/search/keyword_matcher.cpp @@ -10,7 +10,7 @@ namespace search namespace impl { -KeywordMatcher::KeywordMatcher(strings::UniString * pKeywords, +KeywordMatcher::KeywordMatcher(strings::UniString const * pKeywords, size_t keywordsCount, strings::UniString const & prefix, uint32_t maxKeywordMatchCost, uint32_t maxPrefixMatchCost, diff --git a/search/keyword_matcher.hpp b/search/keyword_matcher.hpp index 7bb0457dd9..434b0ea4aa 100644 --- a/search/keyword_matcher.hpp +++ b/search/keyword_matcher.hpp @@ -17,7 +17,7 @@ typedef uint32_t (* StringMatchFn)(strings::UniChar const * sA, uint32_t sizeA, // Matches keywords agains given names. class KeywordMatcher { - strings::UniString * m_pKewords; + strings::UniString const * m_pKewords; strings::UniString const & m_prefix; uint32_t m_maxKeywordMatchCost, m_maxPrefixMatchCost; StringMatchFn m_keywordMatchFn, m_prefixMatchFn; @@ -26,7 +26,7 @@ class KeywordMatcher string m_bestPrefixMatch; public: - KeywordMatcher(strings::UniString * pKeywords, + KeywordMatcher(strings::UniString const * pKeywords, size_t keywordsCount, strings::UniString const & prefix, uint32_t maxKeywordMatchCost, uint32_t maxPrefixMatchCost, diff --git a/search/query.cpp b/search/query.cpp index 6390f0917a..c5e1aa41a8 100644 --- a/search/query.cpp +++ b/search/query.cpp @@ -63,7 +63,8 @@ struct FeatureProcessor uint32_t const maxKeywordMatchScore = 512; uint32_t const maxPrefixMatchScore = min(static_cast(maxKeywordMatchScore), 256 * max(0, int(m_query.m_prefix.size()) - 1)); - KeywordMatcher matcher(&m_query.m_keywords[0], m_query.m_keywords.size(), m_query.m_prefix, + size_t const kwSize = m_query.m_keywords.size(); + KeywordMatcher matcher(kwSize ? &m_query.m_keywords[0] : NULL, kwSize, m_query.m_prefix, maxKeywordMatchScore, maxPrefixMatchScore, &KeywordMatch, &PrefixMatch); feature.ForEachNameRef(matcher);