[igt-dev] [PATCH i-g-t 06/21] lib: Avoid memcpying 0 bytes from NULL
Petri Latvala
petri.latvala at intel.com
Wed Jan 16 11:20:35 UTC 2019
The behaviour of memcpying 0 bytes from NULL is semantically sound,
but still undefined behaviour.
Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
lib/igt_core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
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,
--
2.19.1
More information about the igt-dev
mailing list