diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-06 15:08:29 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-06 15:08:29 +0000 |
commit | edaf5136db5f14c1a1595c4c6a9a82ea22548aca (patch) | |
tree | 7a0c6e421c9b3ee16d4f59d96a5b222ae3875a42 /searchlib | |
parent | 8e9ec7f77efecfa970b58568f024a118122b334e (diff) |
- Improve sanity checking of input to distance-to-path feature.
- Keep comment
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/features/prod_features.cpp | 9 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/features/distancetopathfeature.cpp | 9 |
2 files changed, 9 insertions, 9 deletions
diff --git a/searchlib/src/tests/features/prod_features.cpp b/searchlib/src/tests/features/prod_features.cpp index 81c46558381..4ebc94ccb8b 100644 --- a/searchlib/src/tests/features/prod_features.cpp +++ b/searchlib/src/tests/features/prod_features.cpp @@ -828,13 +828,12 @@ struct AirPort { }; std::pair<int32_t, int32_t> toXY(const AirPort &p) { - return std::make_pair((int)(p.lng * 1.0e6), - (int)(p.lat * 1.0e6)); + return std::make_pair(int(p.lng * 1.0e6), int(p.lat * 1.0e6)); } GeoLocation toGL(const AirPort &p) { - int32_t x = (int)(p.lng * 1.0e6); - int32_t y = (int)(p.lat * 1.0e6); + auto x = int(p.lng * 1.0e6); + auto y = int(p.lat * 1.0e6); GeoLocation::Point gp{x, y}; return GeoLocation{gp}; } @@ -1054,6 +1053,8 @@ Test::testDistanceToPath() pos.emplace_back(0, 0); // invalid path + assertDistanceToPath(pos, ""); + assertDistanceToPath(pos, "()"); assertDistanceToPath(pos, "a"); assertDistanceToPath(pos, "("); assertDistanceToPath(pos, "(a"); diff --git a/searchlib/src/vespa/searchlib/features/distancetopathfeature.cpp b/searchlib/src/vespa/searchlib/features/distancetopathfeature.cpp index b39e9358a00..3469d776960 100644 --- a/searchlib/src/vespa/searchlib/features/distancetopathfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/distancetopathfeature.cpp @@ -49,7 +49,7 @@ DistanceToPathExecutor::execute(uint32_t docId) double len = std::sqrt(len2); // For each document location, do - for (long loc : _intBuf) { + for (auto loc : _intBuf) { int32_t x = 0, y = 0; vespalib::geo::ZCurve::decode(loc, &x, &y); @@ -108,7 +108,7 @@ DistanceToPathBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment search::fef::Blueprint::UP DistanceToPathBlueprint::createInstance() const { - return Blueprint::UP(new DistanceToPathBlueprint()); + return std::make_unique<DistanceToPathBlueprint>(); } bool @@ -133,11 +133,10 @@ DistanceToPathBlueprint::createExecutor(const search::fef::IQueryEnvironment &en if (pro.found()) { vespalib::stringref str = pro.getAt(0); uint32_t len = str.size(); - if (str[0] == '(' && len > 1 && str[len - 1] == ')') { + if ((len > 1) && (str[0] == '(') && (str[len - 1] == ')')) { str = str.substr(1, len - 1); // remove braces vespalib::StringTokenizer tokenizer(str); - len = tokenizer.size() - 1; - for (uint32_t i = 0; i < len; i += 2) { + for (uint32_t i = 0; (i + 2) <= tokenizer.size(); i += 2) { auto x = util::strToNum<double>(tokenizer[i]); auto y = util::strToNum<double>(tokenizer[i + 1]); path.emplace_back(x, y); |