Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Hurd: remove VLA usage.
@ 2024-12-18  6:27 Flavio Cruz
  2024-12-18 15:14 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Flavio Cruz @ 2024-12-18  6:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Compilation will fail with -Werror=vla, which seems to be the default.

Note that we can allocate just an array of num_threads pointers,
hence the change.
---
 gdb/gnu-nat.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index a8a4da1c..60819695 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -1016,14 +1016,14 @@ gnu_nat_target::inf_validate_procs (struct inf *inf)
   {
     /* Make things normally linear.  */
     mach_msg_type_number_t search_start = 0;
-    /* Which thread in PROCS corresponds to each task thread, & the task.  */
-    struct proc *matched[num_threads + 1];
+    /* Which thread in PROCS corresponds to each task thread.  */
+    struct proc **matched = XNEWVEC (struct proc *, num_threads);
     /* The last thread in INF->threads, so we can add to the end.  */
     struct proc *last = 0;
     /* The current thread we're considering.  */
     struct proc *thread = inf->threads;
 
-    memset (matched, 0, sizeof (matched));
+    memset (matched, 0, sizeof (struct proc *) * num_threads);
 
     while (thread)
       {
@@ -1090,6 +1090,7 @@ gnu_nat_target::inf_validate_procs (struct inf *inf)
 	  }
       }
 
+    xfree (matched);
     vm_deallocate (mach_task_self (),
 		   (vm_address_t) threads, (num_threads * sizeof (thread_t)));
   }
-- 
2.45.2


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

* Re: [PATCH] Hurd: remove VLA usage.
  2024-12-18  6:27 [PATCH] Hurd: remove VLA usage Flavio Cruz
@ 2024-12-18 15:14 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2024-12-18 15:14 UTC (permalink / raw)
  To: Flavio Cruz; +Cc: gdb-patches, Tom Tromey

>>>>> "Flavio" == Flavio Cruz <flaviocruz@gmail.com> writes:

Flavio> Compilation will fail with -Werror=vla, which seems to be the default.
Flavio> Note that we can allocate just an array of num_threads pointers,
Flavio> hence the change.

Flavio> -    /* Which thread in PROCS corresponds to each task thread, & the task.  */
Flavio> -    struct proc *matched[num_threads + 1];
Flavio> +    /* Which thread in PROCS corresponds to each task thread.  */
Flavio> +    struct proc **matched = XNEWVEC (struct proc *, num_threads);

Since this is in C++ code I think you could use

    std::vector<proc *> matched (num_threads + 1, nullptr);

Flavio> +    xfree (matched);

... that would avoid the explicit free.

Tom

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

end of thread, other threads:[~2024-12-18 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-18  6:27 [PATCH] Hurd: remove VLA usage Flavio Cruz
2024-12-18 15:14 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox