From 678228976168f2fb94539f9912eadda4a90d97ff Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Fri, 28 May 2021 20:05:12 +0300 Subject: [PATCH] X3: Fix seek goes past the end of input Reverts #30. Fixes #658. --- include/boost/spirit/home/x3/directive/seek.hpp | 15 ++++----------- repository/test/qi/seek.cpp | 3 +++ test/x3/seek.cpp | 3 +++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/boost/spirit/home/x3/directive/seek.hpp b/include/boost/spirit/home/x3/directive/seek.hpp index a71669807..d78def1c2 100644 --- a/include/boost/spirit/home/x3/directive/seek.hpp +++ b/include/boost/spirit/home/x3/directive/seek.hpp @@ -28,25 +28,18 @@ namespace boost { namespace spirit { namespace x3 Iterator& first, Iterator const& last , Context const& context, RContext& rcontext, Attribute& attr) const { - Iterator current(first); - for (/**/; current != last; ++current) + for (Iterator current(first);; ++current) { if (this->subject.parse(current, last, context, rcontext, attr)) { first = current; return true; } - } - // Test for when subjects match on input empty. Example: - // comment = "//" >> seek[eol | eoi] - if (this->subject.parse(current, last, context, rcontext, attr)) - { - first = current; - return true; + // fail only after subject fails & no input + if (current == last) + return false; } - - return false; } }; diff --git a/repository/test/qi/seek.cpp b/repository/test/qi/seek.cpp index 96183024f..02f9a8e7c 100644 --- a/repository/test/qi/seek.cpp +++ b/repository/test/qi/seek.cpp @@ -97,5 +97,8 @@ int main() ); } + // past the end regression GH#658 + BOOST_TEST(!test(" ", seek['x'], space)); + return boost::report_errors(); } diff --git a/test/x3/seek.cpp b/test/x3/seek.cpp index 23925b427..69ca10fee 100644 --- a/test/x3/seek.cpp +++ b/test/x3/seek.cpp @@ -93,5 +93,8 @@ int main() BOOST_TEST(test_failure("abcdefg", x3::seek[x3::int_])); } + // past the end regression GH#658 + BOOST_TEST(!test(" ", x3::seek['x'], x3::space)); + return boost::report_errors(); }