Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz at gmail.com>
To: iwd at lists.01.org
Subject: Re: [PATCH] src/sae.c: Use realloc(3) instead of reallocarray(3)
Date: Sun, 19 Sep 2021 12:54:39 -0500	[thread overview]
Message-ID: <a79af225-e17c-7207-9f2c-024ea3dca56f@gmail.com> (raw)
In-Reply-To: 20210919085710.1805075-1-fontaine.fabrice@gmail.com

[-- Attachment #1: Type: text/plain, Size: 2074 bytes --]

Hi Fabrice,

On 9/19/21 3:57 AM, Fabrice Fontaine wrote:
> reallocarray(3) has been added to glibc relatively recently (version
> 2.26, from 2017) and apparently not all users run new enough glibc.
> Moreover, reallocarray is not available with uclibc-ng. Just use
> realloc(3) for now since in this case there's no real risk of overflow.
> This will avoid the following build failure since commit
> 891b78e9e892a3bcd800eb3a298e6380e9a15dd1:
> 
> /home/giuliobenetti/autobuild/run/instance-3/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/10.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: src/sae.o: in function `sae_rx_authenticate':
> sae.c:(.text+0xd74): undefined reference to `reallocarray'
> 
> Fixes:
>   - http://autobuild.buildroot.org/results/c6d3f86282c44645b4f1c61882dc63ccfc8eb35a
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice(a)gmail.com>

No S-o-b tags please.

> ---
>   src/sae.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/sae.c b/src/sae.c
> index 7e6377f5..d04891e7 100644
> --- a/src/sae.c
> +++ b/src/sae.c
> @@ -104,7 +104,7 @@ static void sae_rejected_groups_append(struct sae_sm *sm, uint16_t group)
>   	uint16_t i;
>   
>   	if (!sm->rejected_groups) {
> -		sm->rejected_groups = reallocarray(NULL, 2, sizeof(uint16_t));
> +		sm->rejected_groups = realloc(NULL, 2 * sizeof(uint16_t));
>   		sm->rejected_groups[0] = 1;
>   		sm->rejected_groups[1] = group;
>   		return;
> @@ -114,8 +114,8 @@ static void sae_rejected_groups_append(struct sae_sm *sm, uint16_t group)
>   		if (sm->rejected_groups[i] == group)
>   			return;
>   
> -	sm->rejected_groups = reallocarray(sm->rejected_groups,
> -						i + 1, sizeof(uint16_t));
> +	sm->rejected_groups = realloc(sm->rejected_groups,
> +					(i + 1) * sizeof(uint16_t));

Can we add this to missing.h instead?  The reallocarray version is more clear / 
preferable to open-coded version.

>   	sm->rejected_groups[0] += 1;
>   	sm->rejected_groups[i] = group;
>   }
> 

Regards,
-Denis

             reply	other threads:[~2021-09-19 17:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-19 17:54 Denis Kenzior [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-09-19 18:19 [PATCH] src/sae.c: Use realloc(3) instead of reallocarray(3) Fabrice Fontaine
2021-09-19  8:57 Fabrice Fontaine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a79af225-e17c-7207-9f2c-024ea3dca56f@gmail.com \
    --to=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox