* [PATCH] Fix off-by-one error in ada_fold_name
@ 2020-12-08 21:25 Kevin Buettner
2020-12-09 21:03 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2020-12-08 21:25 UTC (permalink / raw)
To: gdb-patches
I'm seeing a libstdc++ assertion failure when running GDB's "maint selftest"
command when GDB is configured with the following CFLAGS and CXXFLAGS as
part of the configure line:
CFLAGS='-D_GLIBCXX_DEBUG -g3 -O0' CXXFLAGS='-D_GLIBCXX_DEBUG -g3 -O0'
This is what I see when running the self tests:
(gdb) maint selftest
Running selftest aarch64-analyze-prologue.
Running selftest aarch64-process-record.
Running selftest arm-record.
Running selftest arm_analyze_prologue.
Running selftest array_view.
Running selftest child_path.
Running selftest cli_utils.
Running selftest command_structure_invariants.
Running selftest copy_bitwise.
Running selftest copy_integer_to_size.
Running selftest cp_remove_params.
Running selftest cp_symbol_name_matches.
Running selftest dw2_expand_symtabs_matching.
/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.
Aborted (core dumped)
Here's a partial stack trace:
#0 0x00007ffff6ef6262 in raise () from /lib64/libc.so.6
#1 0x00007ffff6edf8a4 in abort () from /lib64/libc.so.6
#2 0x00000000004249bf in std::__replacement_assert (
__file=0xef7480 "/usr/include/c++/11/string_view", __line=211,
__function=0xef7328 "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::ba"...,
__condition=0xef7311 "__pos < this->_M_len")
at /usr/include/c++/11/x86_64-redhat-linux/bits/c++config.h:2624
#3 0x0000000000451737 in std::basic_string_view<char, std::char_traits<char> >::operator[] (this=0x7fffffffc200, __pos=8)
at /usr/include/c++/11/string_view:211
#4 0x00000000004329f5 in ada_fold_name (name="function")
at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988
And, looking at frame #4...
(top-gdb) up 4
at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988
988 fold_buffer[i] = tolower (name[i]);
(top-gdb) p i
$1 = 8
(top-gdb) p name.size()
$2 = 8
My patch adjusts the comparison to only copy name.size() characters
from the string. I've added a separate statement for NUL character
termination of fold_buffer[].
gdb/ChangeLog:
* ada-lang.c (ada_fold_name): Fix off-by-one error.
---
gdb/ada-lang.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8a1d9df541..b416c8d74d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -984,8 +984,9 @@ ada_fold_name (gdb::string_view name)
{
int i;
- for (i = 0; i <= len; i += 1)
+ for (i = 0; i < len; i += 1)
fold_buffer[i] = tolower (name[i]);
+ fold_buffer[i] = '\0';
}
return fold_buffer;
--
2.28.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix off-by-one error in ada_fold_name
2020-12-08 21:25 [PATCH] Fix off-by-one error in ada_fold_name Kevin Buettner
@ 2020-12-09 21:03 ` Tom Tromey
2020-12-10 21:23 ` Kevin Buettner
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-12-09 21:03 UTC (permalink / raw)
To: Kevin Buettner via Gdb-patches
>>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:
Kevin> gdb/ChangeLog:
Kevin> * ada-lang.c (ada_fold_name): Fix off-by-one error.
Thank you. This looks good.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix off-by-one error in ada_fold_name
2020-12-09 21:03 ` Tom Tromey
@ 2020-12-10 21:23 ` Kevin Buettner
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Buettner @ 2020-12-10 21:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
On Wed, 09 Dec 2020 14:03:50 -0700
Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Kevin> gdb/ChangeLog:
>
> Kevin> * ada-lang.c (ada_fold_name): Fix off-by-one error.
>
> Thank you. This looks good.
Thanks for looking it over.
I've pushed this change.
Kevin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-10 21:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 21:25 [PATCH] Fix off-by-one error in ada_fold_name Kevin Buettner
2020-12-09 21:03 ` Tom Tromey
2020-12-10 21:23 ` Kevin Buettner
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).