Blame SOURCES/gdb-rhbz1912985-libstdc++-assert.patch

132741
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
132741
From: Kevin Buettner <kevinb@redhat.com>
132741
Date: Wed, 17 Feb 2021 17:58:54 -0700
132741
Subject: gdb-rhbz1912985-libstdc++-assert.patch
132741
132741
;; Backport fix for libstdc++ assert when performing tab completion
132741
;; (RH BZ 1912985).
132741
132741
Fix completion related libstdc++ assert when using -D_GLIBCXX_DEBUG
132741
132741
This commit fixes a libstdc++ assertion failure encountered when
132741
running gdb.base/completion.exp.  In order to see this problem,
132741
GDB must be built with the follow CFLAGS and CXXFLAGS as part
132741
of the configure line:
132741
132741
  CFLAGS='-D_GLIBCXX_DEBUG' CXXFLAGS='-D_GLIBCXX_DEBUG'
132741
132741
(Also, this problem was encountered using Fedora rawhide.  It might
132741
not be reproducible in Fedora versions prior to Fedora 34.)
132741
132741
Using the gdb.base/completion.exp test program, the problem can be
132741
observed as follows:
132741
132741
[kev@rawhide-1 gdb]$ ./gdb -q testsuite/outputs/gdb.base/completion/completion
132741
Reading symbols from testsuite/outputs/gdb.base/completion/completion...
132741
(gdb) start
132741
Temporary breakpoint 1 at 0x401179: file ../../worktree-master/gdb/testsuite/gdb.base/break.c, line 43.
132741
Starting program: testsuite/outputs/gdb.base/completion/completion
132741
132741
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd718, envp=0x7fffffffd728) at ../../worktree-master/gdb/testsuite/gdb.base/break.c:43
132741
43	    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
132741
(gdb) p <TAB>/usr/include/c++/11/string_view:211: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
132741
Aborted (core dumped)
132741
132741
(Note that I added "<TAB>" to make it clear where the tab key was
132741
pressed.)
132741
132741
gdb/ChangeLog:
132741
132741
	* ada-lang.c (ada_fold_name): Check for non-empty string prior
132741
	to accessing it.
132741
	(ada_lookup_name_info): Likewise.
132741
132741
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
132741
--- a/gdb/ada-lang.c
132741
+++ b/gdb/ada-lang.c
132741
@@ -997,7 +997,7 @@ ada_fold_name (gdb::string_view name)
132741
   int len = name.size ();
132741
   GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
132741
 
132741
-  if (name[0] == '\'')
132741
+  if (!name.empty () && name[0] == '\'')
132741
     {
132741
       strncpy (fold_buffer, name.data () + 1, len - 2);
132741
       fold_buffer[len - 2] = '\000';
132741
@@ -13597,7 +13597,7 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
132741
 {
132741
   gdb::string_view user_name = lookup_name.name ();
132741
 
132741
-  if (user_name[0] == '<')
132741
+  if (!user_name.empty () && user_name[0] == '<')
132741
     {
132741
       if (user_name.back () == '>')
132741
 	m_encoded_name