dcb: Fix compilation warning about reallocarray
Subsystems (2)
PATCH v2 1/1 dcb: Fix compilation warning about reallocarray
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’?
---
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(-)
dcb/dcb_app.c +1 -2
@@ -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" );
Signature · 1 line
2.8.0
dcb/dcb_app.c static void dcb_app_table_fini(struct dcb_app_table *tab) · line 68
Quoted 9 lines · Roi Dayan
dcb/dcb_app.c +1
-2@@ -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.
Quoted 6 lines · Petr Machata
Quoted 4 lines · Roi Dayan
dcb/dcb_app.c +0
-0@@ -65,8 +65,7 @@ static void dcb_app_table_fini(struct dcb_app_table *tab)
Quoted 7 lines
dcb/dcb_app.c static void dcb_app_table_fini(struct dcb_app_table *tab) · line 68
Quoted 5 lines
dcb/dcb_app.c +1
-2static 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 <[email protected]>
Could this be merged, please?
Quoted 1 line · Petr Machata
Could this be merged, please?
done