[7/7] test/bers: Fix sizeof to memset

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

Details

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

Commit Message

Rikard Falkeborn April 28, 2019, 6:22 p.m.
sizeof(fd) is the size of the pointer. Make sure the entire array is set
by using the number of elements times the size of the elements.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 test/others/bers/bers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/others/bers/bers.c b/test/others/bers/bers.c
index 0954868f..90b70c34 100644
--- a/test/others/bers/bers.c
+++ b/test/others/bers/bers.c
@@ -138,7 +138,7 @@  static int create_files(shared_data_t *shared, int *fd, size_t nr_files)
 	char path[PATH_MAX];
 	size_t i;
 
-	memset(fd, 0xff, sizeof(fd));
+	memset(fd, 0xff, sizeof(*fd) * MAX_CHUNK);
 
 	pr_info("\tCreating %lu files\n", shared->opt_files);
 

Comments

Dmitry Safonov April 29, 2019, 2:59 p.m.
On Sun, 28 Apr 2019 at 19:45, Rikard Falkeborn
<rikard.falkeborn@gmail.com> wrote:
>
> sizeof(fd) is the size of the pointer. Make sure the entire array is set
> by using the number of elements times the size of the elements.
>
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>

We could set only nr_files instead of MAX_CHUNK, but it's a test,
so I don't actually mind setting the whole array. Thanks,
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>

> ---
>  test/others/bers/bers.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/others/bers/bers.c b/test/others/bers/bers.c
> index 0954868f..90b70c34 100644
> --- a/test/others/bers/bers.c
> +++ b/test/others/bers/bers.c
> @@ -138,7 +138,7 @@ static int create_files(shared_data_t *shared, int *fd, size_t nr_files)
>         char path[PATH_MAX];
>         size_t i;
>
> -       memset(fd, 0xff, sizeof(fd));
> +       memset(fd, 0xff, sizeof(*fd) * MAX_CHUNK);
>
>         pr_info("\tCreating %lu files\n", shared->opt_files);
>
> --
> 2.21.0
>
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu