dt_cg_store_var() needs to copy terminating NUL byte for strings
Consider /* * Determine the amount of data to be copied. It is * the lesser of the size of the identifier and the * size of the data being copied in. */ srcsz = dt_node_type_size(dnp->dn_right); if (dt_node_is_string(dnp)) srcsz += DT_STRLEN_BYTES; size = MIN(srcsz, size);
"srcsz = dt_node_type_size(dnp->dn_right)" includes the terminating NUL byte for string constants but not for regular string types.
"size = idp->di_size" generally will not include the NUL terminating byte either.
Check and fix this code on both the gvar/lvar and the tvar code paths.
This will require additional audit because functions that return the size of a type need to be consistent (and all code that uses them needs to obviously follow that convention). It would seem reasonable to have the type size return the total storage size, i.e. DT_STRLEN_BYTES + strlen(str) + 1, and adjust the calling sites accordingly. Similarly, idp->di_size should probably use the same value, and uses should adjust to that. Perhaps the introduction of some macro(s) can assist in not having too many instances of adding or subtracting the DT_STLREN_BYTES and.or the terminating byte.