public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove alloca from osabi.c
@ 2023-08-14 16:48 Tom Tromey
  2023-08-14 17:48 ` John Baldwin
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2023-08-14 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I noticed that the call to alloca in osabi.c can be replaced with a
statically-sized buffer, because some code just before the declaration
ensures that the length is bounded.
---
 gdb/osabi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gdb/osabi.c b/gdb/osabi.c
index d18802ac3a4..ad3dad5b849 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -463,7 +463,6 @@ generic_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
 {
   const char *name;
   unsigned int sectsize;
-  char *note;
 
   name = bfd_section_name (sect);
   sectsize = bfd_section_size (sect);
@@ -477,7 +476,7 @@ generic_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
      compressed section.  But, since note sections are not compressed,
      deferring the reading until we recognize the section avoids any
      error.  */
-  note = (char *) alloca (sectsize);
+  char note[MAX_NOTESZ];
 
   /* .note.ABI-tag notes, used by GNU/Linux and FreeBSD.  */
   if (strcmp (name, ".note.ABI-tag") == 0)
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Remove alloca from osabi.c
  2023-08-14 16:48 [PATCH] Remove alloca from osabi.c Tom Tromey
@ 2023-08-14 17:48 ` John Baldwin
  0 siblings, 0 replies; 2+ messages in thread
From: John Baldwin @ 2023-08-14 17:48 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 8/14/23 9:48 AM, Tom Tromey wrote:
> I noticed that the call to alloca in osabi.c can be replaced with a
> statically-sized buffer, because some code just before the declaration
> ensures that the length is bounded.
> ---
>   gdb/osabi.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/gdb/osabi.c b/gdb/osabi.c
> index d18802ac3a4..ad3dad5b849 100644
> --- a/gdb/osabi.c
> +++ b/gdb/osabi.c
> @@ -463,7 +463,6 @@ generic_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
>   {
>     const char *name;
>     unsigned int sectsize;
> -  char *note;
>   
>     name = bfd_section_name (sect);
>     sectsize = bfd_section_size (sect);
> @@ -477,7 +476,7 @@ generic_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
>        compressed section.  But, since note sections are not compressed,
>        deferring the reading until we recognize the section avoids any
>        error.  */
> -  note = (char *) alloca (sectsize);
> +  char note[MAX_NOTESZ];
>   
>     /* .note.ABI-tag notes, used by GNU/Linux and FreeBSD.  */
>     if (strcmp (name, ".note.ABI-tag") == 0)

Reviewed-by: John Baldwin <jhb@FreeBSD.org>

-- 
John Baldwin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-14 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-14 16:48 [PATCH] Remove alloca from osabi.c Tom Tromey
2023-08-14 17:48 ` John Baldwin

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).