From 6dbbd277d900c2d8fc1be7b0c60e82843c554418 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 24 Feb 2017 10:51:05 +1100 Subject: libfdt: Remove undefined behaviour setting empty properties The standard way of setting an empty property using libfdt is: fdt_setprop(fdt, nodeoffset, propname, NULL, 0); However, the implementation of this includes an unconditional: memcpy(prop->data, NULL, 0); Which although it will be a no-op (which is what we want) on many platforms is technically undefined behaviour. Correct this, so that when passing a 0 length, passing a NULL pointer as the value to fdt_setprop() is definitely safe. This should quiet static checkers which complain about this. Signed-off-by: David Gibson --- cpukit/dtc/libfdt/fdt_rw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cpukit') diff --git a/cpukit/dtc/libfdt/fdt_rw.c b/cpukit/dtc/libfdt/fdt_rw.c index 2eed4f5838..3fd5847377 100644 --- a/cpukit/dtc/libfdt/fdt_rw.c +++ b/cpukit/dtc/libfdt/fdt_rw.c @@ -283,7 +283,8 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, if (err) return err; - memcpy(prop->data, val, len); + if (len) + memcpy(prop->data, val, len); return 0; } -- cgit v1.2.3