[v2] Hurd: remove VLA usage.

Message ID aj4yb3tl24xtqrfuxciapl5loamna73cy7k2724gzwaccc6lyk@heqjutt4r6g5
State New
Headers
Series [v2] Hurd: remove VLA usage. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply

Commit Message

Flávio Cruz Dec. 22, 2024, 5:34 a.m. UTC
  Compilation will fail with -Werror=vla, which seems to be the default.

Note that we don't need to allocate num_threads + 1 since the matching
algorithm works only on the num_threads as returned by task_threads.
---
 gdb/gnu-nat.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Simon Marchi Dec. 22, 2024, 2:26 p.m. UTC | #1
On 2024-12-22 00:34, Flavio Cruz wrote:
> Compilation will fail with -Werror=vla, which seems to be the default.
> 
> Note that we don't need to allocate num_threads + 1 since the matching
> algorithm works only on the num_threads as returned by task_threads.
> ---
>  gdb/gnu-nat.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
> index a8a4da1c..ab157094 100644
> --- a/gdb/gnu-nat.c
> +++ b/gdb/gnu-nat.c
> @@ -1016,15 +1016,13 @@ 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.  */
> +    std::vector<struct proc *> matched (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));
> -
>      while (thread)
>        {
>  	mach_msg_type_number_t left;

Thanks, I pushed that for you.  I made a minor modification, adding
newlines before the comments between the declarations.

Simon
  

Patch

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index a8a4da1c..ab157094 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -1016,15 +1016,13 @@  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.  */
+    std::vector<struct proc *> matched (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));
-
     while (thread)
       {
 	mach_msg_type_number_t left;