[U-Boot] [PATCH 1/1] kconfig/symbol.c: use correct pointer type argument for sizeof

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Nov 9 07:12:32 UTC 2017


On 11/09/2017 03:01 AM, Tom Rini wrote:
> On Wed, Nov 08, 2017 at 10:13:54PM +0100, Heinrich Schuchardt wrote:
>> sym_arr is of type struct symbol **.
>> So in malloc we need sizeof(struct symbol *).
>>
>> The problem was indicated by coccinelle.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
>> ---
>>   scripts/kconfig/symbol.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
>> index 20136ffefb..3c8bd9bb42 100644
>> --- a/scripts/kconfig/symbol.c
>> +++ b/scripts/kconfig/symbol.c
>> @@ -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


More information about the U-Boot mailing list