diff mbox series

efi_loader: capsule: fix SIZEOF_MISMATCH warning

Message ID 20210122014327.20589-1-takahiro.akashi@linaro.org
State Accepted
Commit 8f1844c3335be8bcf22de63057cf8f0c11416d00
Headers show
Series efi_loader: capsule: fix SIZEOF_MISMATCH warning | expand

Commit Message

AKASHI Takahiro Jan. 22, 2021, 1:43 a.m. UTC
CID 316361 says:
> Passing argument "count * 8UL /* sizeof (*files) */" to

> function "dlmalloc" and then casting the return value to "u16 **" is

> suspicious. In this particular case "sizeof (u16 **)" happens to be equal

> to "sizeof (u16 *)", but this is not a portable assumption.

> > 767         tmp_files = malloc(count * sizeof(*files));


The change in this patch fixes the ambiguity.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

Fixes: CID 316361
---
 lib/efi_loader/efi_capsule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.28.0

Comments

Heinrich Schuchardt Jan. 22, 2021, 5:45 a.m. UTC | #1
On 1/22/21 2:43 AM, AKASHI Takahiro wrote:
> CID 316361 says:

>> Passing argument "count * 8UL /* sizeof (*files) */" to

>> function "dlmalloc" and then casting the return value to "u16 **" is

>> suspicious. In this particular case "sizeof (u16 **)" happens to be equal

>> to "sizeof (u16 *)", but this is not a portable assumption.

>>> 767         tmp_files = malloc(count * sizeof(*files));

>

> The change in this patch fixes the ambiguity.

>

> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

> Fixes: CID 316361


Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


> ---

>   lib/efi_loader/efi_capsule.c | 2 +-

>   1 file changed, 1 insertion(+), 1 deletion(-)

>

> diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c

> index dad1b0fcf7c0..95413c50f89a 100644

> --- a/lib/efi_loader/efi_capsule.c

> +++ b/lib/efi_loader/efi_capsule.c

> @@ -764,7 +764,7 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)

>   		goto err;

>

>   	/* make a list */

> -	tmp_files = malloc(count * sizeof(*files));

> +	tmp_files = malloc(count * sizeof(tmp_files[0]));

>   	if (!tmp_files) {

>   		ret = EFI_OUT_OF_RESOURCES;

>   		goto err;

>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index dad1b0fcf7c0..95413c50f89a 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -764,7 +764,7 @@  static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)
 		goto err;
 
 	/* make a list */
-	tmp_files = malloc(count * sizeof(*files));
+	tmp_files = malloc(count * sizeof(tmp_files[0]));
 	if (!tmp_files) {
 		ret = EFI_OUT_OF_RESOURCES;
 		goto err;