From 009d7bd524aaa45e0910c3254b6ed47c0fc9e68c Mon Sep 17 00:00:00 2001 From: Petri Latvala Date: Wed, 16 Jan 2019 13:20:35 +0200 Subject: lib: Avoid memcpying 0 bytes from NULL The behaviour of memcpying 0 bytes from NULL is semantically sound, but still undefined behaviour. Signed-off-by: Petri Latvala Cc: Arkadiusz Hiler Reviewed-by: Arkadiusz Hiler --- lib/igt_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/igt_core.c') diff --git a/lib/igt_core.c b/lib/igt_core.c index 50d6008f..7c727edc 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -728,8 +728,9 @@ static int common_init(int *argc, char **argv, all_opt_count += ARRAY_SIZE(long_options); combined_opts = malloc(all_opt_count * sizeof(*combined_opts)); - memcpy(combined_opts, extra_long_opts, - extra_opt_count * sizeof(*combined_opts)); + if (extra_opt_count > 0) + memcpy(combined_opts, extra_long_opts, + extra_opt_count * sizeof(*combined_opts)); /* Copy the subtest long options (and the final NULL entry) */ memcpy(&combined_opts[extra_opt_count], long_options, -- cgit v1.2.3