public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-4326] libstdc++: Add valid range assertions to std::basic_regex [PR89927]
Date: Mon, 11 Oct 2021 19:37:23 +0000 (GMT)	[thread overview]
Message-ID: <20211011193723.096FC3858430@sourceware.org> (raw)

https://gcc.gnu.org/g:6b6788f8c2748060d922cc22173ff7f8500917e9

commit r12-4326-g6b6788f8c2748060d922cc22173ff7f8500917e9
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Oct 11 12:08:59 2021 +0100

    libstdc++: Add valid range assertions to std::basic_regex [PR89927]
    
    This adds some debug assertions to basic_regex. They don't actually
    diagnose the error in the PR yet, but I have another patch to make them
    more effective.
    
    Also change the __glibcxx_assert(false) consistency checks to include a
    string literal that tells the user a bit more about why the process
    aborted. We could consider adding a __glibcxx_bug or
    __glibcxx_internal_error macro for this purpose, but ideally we'll never
    hit such bugs anyway so it shouldn't be needed.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/89927
            * include/bits/regex.h (basic_regex(const _Ch_type*, size_t)):
            Add __glibcxx_requires_string_len assertion.
            (basic_regex::assign(InputIterator, InputIterator)): Add
            __glibcxx_requires_valid_range assertion.
            * include/bits/regex_scanner.tcc (_Scanner::_M_advance())
            (_Scanner::_M_scan_normal()): Use string literal in assertions.

Diff:
---
 libstdc++-v3/include/bits/regex.h           | 6 +++++-
 libstdc++-v3/include/bits/regex_scanner.tcc | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index bf02bff7c49..3c44bcd7e33 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -467,7 +467,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        */
       basic_regex(const _Ch_type* __p, std::size_t __len,
 		  flag_type __f = ECMAScript)
-      { _M_compile(__p, __p + __len, __f); }
+      {
+	__glibcxx_requires_string_len(__p, __len);
+	_M_compile(__p, __p + __len, __f);
+      }
 
       /**
        * @brief Copy-constructs a basic regular expression.
@@ -684,6 +687,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	  if constexpr (__detail::__is_contiguous_iter<_InputIterator>::value
 			&& is_same_v<_ValT, value_type>)
 	    {
+	      __glibcxx_requires_valid_range(__first, __last);
 	      const auto __len = __last - __first;
 	      const _Ch_type* __p = std::__to_address(__first);
 	      _M_compile(__p, __p + __len, __flags);
diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc
index d81627dc3e9..2fa2303f27b 100644
--- a/libstdc++-v3/include/bits/regex_scanner.tcc
+++ b/libstdc++-v3/include/bits/regex_scanner.tcc
@@ -83,7 +83,7 @@ namespace __detail
 	_M_scan_in_brace();
       else
 	{
-	  __glibcxx_assert(false);
+	  __glibcxx_assert(!"unexpected state while processing regex");
 	}
     }
 
@@ -195,7 +195,7 @@ namespace __detail
 		_M_token = __it->second;
 		return;
 	      }
-	  __glibcxx_assert(false);
+	  __glibcxx_assert(!"unexpected special character in regex");
 	}
       else
 	{


                 reply	other threads:[~2021-10-11 19:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011193723.096FC3858430@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).