aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-12-16 18:06:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-12-16 18:06:59 +0200
commit33a3ad413e3fe805f7dea79b46f58dc27c3ede2e (patch)
treebea931e7cc5486de0a3b17bc19c9a3c586c62aaf
parent753ed6465990b903ae470e1fb5b4f185bfc4be73 (diff)
Check that key is at least as long as prefix in prefix map
-rw-r--r--butl/prefix-map8
1 files changed, 3 insertions, 5 deletions
diff --git a/butl/prefix-map b/butl/prefix-map
index 80264d0..870f251 100644
--- a/butl/prefix-map
+++ b/butl/prefix-map
@@ -46,15 +46,13 @@ namespace butl
return compare (x.c_str (), x.size (), y.c_str (), y.size ()) < 0;
}
- // Note: doesn't check for k.size () being at least p.size ().
- //
bool
prefix (const K& p, const K& k) const
{
- size_type pn (p.size ());
+ size_type pn (p.size ()), kn (k.size ());
return pn == 0 || // Empty key is always a prefix.
- compare (
- p.c_str (), pn, k.c_str (), pn == k.size () ? pn : pn + 1) == 0;
+ (pn <= kn &&
+ compare (p.c_str (), pn, k.c_str (), pn == kn ? pn : pn + 1) == 0);
}
protected: