Skip to contentSkip to conversation

kconfig/symbol.c: use correct pointer type argument for sizeof

PATCH New Heinrich Schuchardt 2 participants 4 messages Nov 8, 2017 – Nov 21, 2017 Kconfig

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig/symbol.c: use correct pointer type argument for sizeof

sym_arr is of type struct symbol **.
So in malloc we need sizeof(struct symbol *).

The problem was indicated by coccinelle.

---
 scripts/kconfig/symbol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +1 -1
index 20136ffefb..3c8bd9bb42 100644
@@ -1061,7 +1061,7 @@ struct symbol **sym_re_search(const char *pattern)
 	}
 	if (sym_match_arr) {
 		qsort(sym_match_arr, cnt, sizeof(struct sym_match), sym_rel_comp);
-		sym_arr = malloc((cnt+1) * sizeof(struct symbol));
+		sym_arr = malloc((cnt+1) * sizeof(struct symbol *));
 		if (!sym_arr)
 			goto sym_re_search_free;
 		for (i = 0; i < cnt; i++)
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/1 kconfig/symbol.c: use correct pointer type argument for sizeof

Quoted 15 lines · Heinrich Schuchardt

sym_arr is of type struct symbol **.
So in malloc we need sizeof(struct symbol *).

The problem was indicated by coccinelle.

---
 scripts/kconfig/symbol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +0 -0
index 20136ffefb..3c8bd9bb42 100644

scripts/kconfig/symbol.c struct symbol **sym_re_search(const char *pattern) · line 1067

Quoted 8 lines
scripts/kconfig/symbol.c +1 -1
@@ -1061,7 +1061,7 @@ struct symbol **sym_re_search(const char *pattern)
 	}
 	if (sym_match_arr) {
 		qsort(sym_match_arr, cnt, sizeof(struct sym_match), sym_rel_comp);
-		sym_arr = malloc((cnt+1) * sizeof(struct symbol));
+		sym_arr = malloc((cnt+1) * sizeof(struct symbol *));
 		if (!sym_arr)
 			goto sym_re_search_free;
 		for (i = 0; i < cnt; i++)

Since this comes right from the kernel, shouldn't it be fixed there too? Or is it already? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171108/3b554ed8/attachment.sig>
#2 lore raw

PATCH 1/1 kconfig/symbol.c: use correct pointer type argument for sizeof

Quoted 11 lines · Tom Rini
Quoted 10 lines · Heinrich Schuchardt

sym_arr is of type struct symbol **.
So in malloc we need sizeof(struct symbol *).

The problem was indicated by coccinelle.

---
  scripts/kconfig/symbol.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines

scripts/kconfig/symbol.c struct symbol **sym_re_search(const char *pattern) · line 1067

Quoted 13 lines
scripts/kconfig/symbol.c +1 -1
index 20136ffefb..3c8bd9bb42 100644
@@ -1061,7 +1061,7 @@ struct symbol **sym_re_search(const char *pattern)
  	}
  	if (sym_match_arr) {
  		qsort(sym_match_arr, cnt, sizeof(struct sym_match), sym_rel_comp);
-		sym_arr = malloc((cnt+1) * sizeof(struct symbol));
+		sym_arr = malloc((cnt+1) * sizeof(struct symbol *));
  		if (!sym_arr)
  			goto sym_re_search_free;
  		for (i = 0; i < cnt; i++)

Since this comes right from the kernel, shouldn't it be fixed there too? Or is it already? Thanks!

I already sent a mail upstream:
https://lkml.org/lkml/2017/11/8/898

Coccinelle indicated a few other problems (using the Linux coccicheck script):
https://patchwork.ozlabs.org/patch/836007/
https://patchwork.ozlabs.org/patch/836008/
https://patchwork.ozlabs.org/patch/836028/
https://patchwork.ozlabs.org/patch/836091/

Scripts like
scripts/coccinelle/iterators/itnull.cocci
are useful to search for API specific issues which generalized static analyzers like cppcheck miss.

To apply coccinelle I just copied scripts/coccicheck and scripts/coccinelle/* from Linux to U-Boot and ran

sudo apt-get install coccinelle
srctree=. scripts/coccicheck

Regards

Heinrich

#3 lore raw

PATCH 1/1 kconfig/symbol.c: use correct pointer type argument for sizeof

In reply to Heinrich Schuchardt
Quoted 6 lines · Heinrich Schuchardt

sym_arr is of type struct symbol **.
So in malloc we need sizeof(struct symbol *).

The problem was indicated by coccinelle.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171121/4a95687a/attachment.sig>