All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray
@ 2021-02-22 12:10 Roi Dayan
  2021-02-22 12:30 ` Petr Machata
  0 siblings, 1 reply; 4+ messages in thread
From: Roi Dayan @ 2021-02-22 12:10 UTC (permalink / raw)
  To: netdev; +Cc: Roi Dayan, Petr Machata, Stephen Hemminger

In older distros we need bsd/stdlib.h but newer distro doesn't
need it. Also old distro will need libbsd-devel installed and newer
doesn't. To remove a possible dependency on libbsd-devel replace usage
of reallocarray to realloc.

dcb_app.c: In function ‘dcb_app_table_push’:
dcb_app.c:68:25: warning: implicit declaration of function ‘reallocarray’; did you mean ‘realloc’?

Fixes: 8e9bed1493f5 ("dcb: Add a subtool for the DCB APP object")
Signed-off-by: Roi Dayan <roid@nvidia.com>
---

Notes:
    v2
    - tag for iproute next
    - replace reallocarray with realloc instead of messing with libbsd

 dcb/dcb_app.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 7ce80f85072b..c4816bc2997f 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -65,8 +65,7 @@ static void dcb_app_table_fini(struct dcb_app_table *tab)
 
 static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
 {
-	struct dcb_app *apps = reallocarray(tab->apps, tab->n_apps + 1,
-					    sizeof(*tab->apps));
+	struct dcb_app *apps = realloc(tab->apps, (tab->n_apps + 1) * sizeof(*tab->apps));
 
 	if (apps == NULL) {
 		perror("Cannot allocate APP table");
-- 
2.8.0


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

* Re: [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray
  2021-02-22 12:10 [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray Roi Dayan
@ 2021-02-22 12:30 ` Petr Machata
  2021-03-15 13:10   ` Petr Machata
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Machata @ 2021-02-22 12:30 UTC (permalink / raw)
  To: Roi Dayan; +Cc: netdev, Petr Machata, Stephen Hemminger


Roi Dayan <roid@nvidia.com> writes:

> --- a/dcb/dcb_app.c
> +++ b/dcb/dcb_app.c
> @@ -65,8 +65,7 @@ static void dcb_app_table_fini(struct dcb_app_table *tab)
>  
>  static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
>  {
> -	struct dcb_app *apps = reallocarray(tab->apps, tab->n_apps + 1,
> -					    sizeof(*tab->apps));
> +	struct dcb_app *apps = realloc(tab->apps, (tab->n_apps + 1) * sizeof(*tab->apps));

reallocarray() checks that count*size does not overflow. But the whole
APP table needs to fit into one attribute, which limits the size to some
64K, so from UAPI direction this will never overflow. From the
command-line direction, size of 'struct app' is 4 bytes, so to overflow
you'd need to stuff in 1G APP entries. I think we don't need to worry
about that.

So this looks good.

Reviewed-by: Petr Machata <petrm@nvidia.com>

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

* Re: [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray
  2021-02-22 12:30 ` Petr Machata
@ 2021-03-15 13:10   ` Petr Machata
  2021-03-15 15:09     ` David Ahern
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Machata @ 2021-03-15 13:10 UTC (permalink / raw)
  To: Petr Machata; +Cc: Roi Dayan, netdev, Stephen Hemminger, David Ahern


Petr Machata <petrm@nvidia.com> writes:

> Roi Dayan <roid@nvidia.com> writes:
>
>> --- a/dcb/dcb_app.c
>> +++ b/dcb/dcb_app.c
>> @@ -65,8 +65,7 @@ static void dcb_app_table_fini(struct dcb_app_table *tab)
>>  
>>  static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
>>  {
>> -	struct dcb_app *apps = reallocarray(tab->apps, tab->n_apps + 1,
>> -					    sizeof(*tab->apps));
>> +	struct dcb_app *apps = realloc(tab->apps, (tab->n_apps + 1) * sizeof(*tab->apps));
>
> Reviewed-by: Petr Machata <petrm@nvidia.com>

Could this be merged, please?

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

* Re: [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray
  2021-03-15 13:10   ` Petr Machata
@ 2021-03-15 15:09     ` David Ahern
  0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2021-03-15 15:09 UTC (permalink / raw)
  To: Petr Machata; +Cc: Roi Dayan, netdev, Stephen Hemminger

On 3/15/21 7:10 AM, Petr Machata wrote:
> Could this be merged, please?

done

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

end of thread, other threads:[~2021-03-15 15:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 12:10 [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray Roi Dayan
2021-02-22 12:30 ` Petr Machata
2021-03-15 13:10   ` Petr Machata
2021-03-15 15:09     ` David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.