[1/7] compel/s390: Fix memset sizeof

Submitted by Rikard Falkeborn on April 28, 2019, 6:22 p.m.

Details

Message ID 20190428182255.5641-2-rikard.falkeborn@gmail.com
State Accepted
Series "Misc fixes found by cppcheck"
Commit c8a597b68d3da87803bf1979ffa6c7901ef2822b
Headers show

Commit Message

Rikard Falkeborn April 28, 2019, 6:22 p.m.
sizeof(sizeof(x)) is the size of size_t. Instead use the size of the
array to ensure the entire array is zeroed.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 compel/arch/s390/src/lib/infect.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/compel/arch/s390/src/lib/infect.c b/compel/arch/s390/src/lib/infect.c
index b690b812..fcb463fa 100644
--- a/compel/arch/s390/src/lib/infect.c
+++ b/compel/arch/s390/src/lib/infect.c
@@ -148,10 +148,8 @@  int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe,
 		memcpy(&dst_ext->vxrs_high, &fpregs->vxrs_high,
 		       sizeof(fpregs->vxrs_high));
 	} else {
-		memset(&dst_ext->vxrs_low, 0,
-		       sizeof(sizeof(fpregs->vxrs_low)));
-		memset(&dst_ext->vxrs_high, 0,
-		       sizeof(sizeof(fpregs->vxrs_high)));
+		memset(&dst_ext->vxrs_low, 0, sizeof(dst_ext->vxrs_low));
+		memset(&dst_ext->vxrs_high, 0, sizeof(dst_ext->vxrs_high));
 	}
 	return 0;
 }

Comments

Dmitry Safonov April 29, 2019, 2:49 p.m.
On Sun, 28 Apr 2019 at 19:45, Rikard Falkeborn
<rikard.falkeborn@gmail.com> wrote:
>
> sizeof(sizeof(x)) is the size of size_t. Instead use the size of the
> array to ensure the entire array is zeroed.
>
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>

Nice find!

Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>

> ---
>  compel/arch/s390/src/lib/infect.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/compel/arch/s390/src/lib/infect.c b/compel/arch/s390/src/lib/infect.c
> index b690b812..fcb463fa 100644
> --- a/compel/arch/s390/src/lib/infect.c
> +++ b/compel/arch/s390/src/lib/infect.c
> @@ -148,10 +148,8 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe,
>                 memcpy(&dst_ext->vxrs_high, &fpregs->vxrs_high,
>                        sizeof(fpregs->vxrs_high));
>         } else {
> -               memset(&dst_ext->vxrs_low, 0,
> -                      sizeof(sizeof(fpregs->vxrs_low)));
> -               memset(&dst_ext->vxrs_high, 0,
> -                      sizeof(sizeof(fpregs->vxrs_high)));
> +               memset(&dst_ext->vxrs_low, 0, sizeof(dst_ext->vxrs_low));
> +               memset(&dst_ext->vxrs_high, 0, sizeof(dst_ext->vxrs_high));
>         }
>         return 0;
>  }
> --
> 2.21.0
>
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu