What's the right way to use libfdt's fdt_setprop to set a property
to have an empty value? At the moment in QEMU we tend to use
  fdt_setprop(fdt, nodeoffset, "propertyname", NULL, 0);

and git grep 'fdt_setprop.*NULL' produces examples of this usage in
PPC and ARM fdt creation code.

However the fdt_setprop() documentation doesn't document that a NULL
value pointer is OK if the length is 0, and indeed the implementation
unconditionally calls memcpy(prop->data, val, len), which is
undefined behaviour, and warned about by clang sanitizers if you
build libfdt with them:
 dtc/libfdt/fdt_rw.c:288:21: runtime error: null pointer passed
   as argument 2, which is declared to never be null

So what's the best thing to do here? I can't offhand think of a
non-ugly/non-confusing way to pass a valid pointer here...

thanks
-- PMM

Reply via email to