From 33a3ad413e3fe805f7dea79b46f58dc27c3ede2e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Dec 2015 18:06:59 +0200 Subject: Check that key is at least as long as prefix in prefix map --- butl/prefix-map | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'butl/prefix-map') 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: -- cgit v1.1