* [PATCH] [gdb/build] Reimplement Wstringop-overread workaround
@ 2026-04-14 13:48 Tom de Vries
2026-04-14 17:38 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-04-14 13:48 UTC (permalink / raw)
To: gdb-patches
While working on commit 391c4026573 ("[gdb] Simplify debuginfod_is_enabled") I
noticed this Wstringop-overread workaround:
...
url_view = url_view.substr (off);
/* g++ 11.2.1 on s390x, g++ 11.3.1 on ppc64le and g++ 11 on
hppa seem convinced url_view might be of SIZE_MAX length.
And so complains because the length of an array can only
be PTRDIFF_MAX. */
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
off = url_view.find_first_of (' ');
DIAGNOSTIC_POP
...
I had difficulty understanding how the warning got triggered, and why it was
ok to ignore it, so I investigated this and ended up filing a gcc PR [1].
While doing so, I realized that this:
...
- url_view = url_view.substr (off);
+ url_view = url_view.substr (off, PTRDIFF_MAX);
...
is a simpler workaround, that:
- is not specific to the warning and also
- states explicitly what the assumption is we're making.
I ended up using this instead to make the workaround part more minimal:
...
url_view = url_view.substr (off);
+#if defined (__GNUC__) && !defined (__clang__)
+ url_view = url_view.substr (0, PTRDIFF_MAX);
+#endif
off = url_view.find_first_of (' ');
...
The gcc PR got closed (because there's no known reproducer with gcc 12 and
later), but I use the workaround without version limit, because there's no
actual proof that the problem is fixed.
Tested on x86_64-linux.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124879
---
gdb/debuginfod-support.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 40b816c5a40..b5e790c3b95 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -249,14 +249,15 @@ debuginfod_is_enabled ()
if (off == std::string_view::npos)
break;
url_view = url_view.substr (off);
- /* g++ 11.2.1 on s390x, g++ 11.3.1 on ppc64le and g++ 11 on
- hppa seem convinced url_view might be of SIZE_MAX length.
- And so complains because the length of an array can only
- be PTRDIFF_MAX. */
- DIAGNOSTIC_PUSH
- DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
+#if defined (__GNUC__) && !defined (__clang__)
+ /* With g++ 11, we encounter a Wstringop-overread in
+ url_view.find_first_of. G++ seems convinced url_view might be of
+ SIZE_MAX length here. And so complains because the length of an
+ array can only be PTRDIFF_MAX. Work around this by explicitly
+ limiting the size of url_view to PTRDIFF_MAX. See PR gcc/124879. */
+ url_view = url_view.substr (0, PTRDIFF_MAX);
+#endif
off = url_view.find_first_of (' ');
- DIAGNOSTIC_POP
gdb_printf
(_(" <%ps>\n"),
styled_string (file_name_style.style (),
base-commit: 391c4026573aeb1e6e09f36816901f2ade537e1a
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/build] Reimplement Wstringop-overread workaround
2026-04-14 13:48 [PATCH] [gdb/build] Reimplement Wstringop-overread workaround Tom de Vries
@ 2026-04-14 17:38 ` Tom Tromey
2026-04-16 10:58 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-04-14 17:38 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> The gcc PR got closed (because there's no known reproducer with gcc 12 and
Tom> later), but I use the workaround without version limit, because there's no
Tom> actual proof that the problem is fixed.
IIUC from the bug, it is believed to have been fixed though right?
Anyway this seems fine to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/build] Reimplement Wstringop-overread workaround
2026-04-14 17:38 ` Tom Tromey
@ 2026-04-16 10:58 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-04-16 10:58 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 4/14/26 7:38 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
Hi Tom,
thanks for the review.
> Tom> The gcc PR got closed (because there's no known reproducer with gcc 12 and
> Tom> later), but I use the workaround without version limit, because there's no
> Tom> actual proof that the problem is fixed.
>
> IIUC from the bug, it is believed to have been fixed though right?
Yes, so I've updated the workaround to trigger only for g++ < 12.1.
> Anyway this seems fine to me.
> Approved-By: Tom Tromey <tom@tromey.com>
Thanks, pushed.
- Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-16 11:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-14 13:48 [PATCH] [gdb/build] Reimplement Wstringop-overread workaround Tom de Vries
2026-04-14 17:38 ` Tom Tromey
2026-04-16 10:58 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox