depmod: always initialize "deps" in mod_get_all_sorted_dependencies()
PATCH 1/1 depmod: always initialize "deps" in mod_get_all_sorted_dependencies()
Fixed Coverity CID #48861
--- tools/depmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/depmod.c +2 -2
@@ -1798,14 +1798,14 @@ static int mod_fill_all_unique_dependencies(const struct mod *mod, const structstatic const struct mod **mod_get_all_sorted_dependencies (const struct mod *mod,size_t *n_deps) { -const struct mod **deps; +const struct mod **deps =NULL ;size_t last =0 ; *n_deps =mod_count_all_dependencies (mod);if (*n_deps ==0 )return NULL ; - deps =malloc (sizeof (struct mod *) * (*n_deps)); + deps =calloc (1 ,sizeof (struct mod *) * (*n_deps));if (deps ==NULL )return NULL ;
Signature · 1 line
2.1.0
Quoted 2 lines · On Sun, Sep 21, 2014 at 9:20 PM, Cristian Rodr=C3=ADguez…
Fixed Coverity CID #48861
---
Is there anything being really fixed here?
tools/depmod.c static int mod_fill_all_unique_dependencies(const=
Quoted 8 lines
tools/depmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/depmod.c +0
-0@@ -1798,14 +1798,14 @@ static int mod_fill_all_unique_dependencies(const=
struct mod *mod, const struct
tools/depmod.c static int mod_fill_all_unique_dependencies(const= · line 1798
Quoted 2 lines
tools/depmod.c +0
-0static const struct mod **mod_get_all_sorted_dependencies(const struct m=
od *mod, size_t *n_deps)
tools/depmod.c static int mod_fill_all_unique_dependencies(const struct mod *mod, const struct
Quoted 3 lines
tools/depmod.c +1
-1{ -const struct mod **deps; + const struct mod **deps =3D NULL;
you are assigning deps to the return of malloc below.
tools/depmod.c static int mod_fill_all_unique_dependencies(const= · line 1807
Quoted 8 lines
tools/depmod.c +1
-1size_t last =3D 0; *n_deps =3D mod_count_all_dependencies(mod); if (*n_deps =3D=3D 0)return NULL ; - deps =3D malloc(sizeof(struct mod *) * (*n_deps)); + deps =3D calloc(1, sizeof(struct mod *) * (*n_deps));
and we are supposed to fill n_deps in mod_fill_all_unique_dependencies() so there's no point in initializing them to 0 here.
--=20
Lucas De Marchi