On Fri, 15 Nov 2019, Markus Elfring wrote: > > --- array-released.diff 2019-11-14 21:29:11.020576916 +0100 > > +++ array-reduced1.diff 2019-11-14 21:45:58.931956527 +0100 > > @@ -6,24 +6,10 @@ > > r->entry_count = t->entry_count; > > r->delta_depth = t->delta_depth; > > - memcpy(r->entries,t->entries,t->entry_count*sizeof(t->entries[0])); > > -+ COPY_ARRAY(r->entries, t->entries, t->entry_count); > > ++ memcpy(r->entries,t->entries,t->entry_count*sizeof(*(t->entries))); > > release_tree_content(t); > > return r; > > } > > It took a while to become more aware of software development challenges > for the safe data processing with the semantic patch language also > at such a source code place. > https://github.com/git/git/blob/3edfcc65fdfc708c1c8f1d314885eecf9beb9b67/fast-import.c#L640 > > I got the impression that the Coccinelle software is occasionally able > to determine from the search specification “sizeof(T)” the corresponding > data type for code like “*(t->entries)”. It can determine the type of t->entries if it has access to the definition of the type of t. This type may be in a header file. If you want Coccinelle to be able to find this information you can use the option --all-includes or --recursive-includes. It will be more efficient with the option --include-headers-for-types. julia > But it seems that there are circumstances to consider where the desired > data type was not automatically determined. > Thus the data processing can become safer by explicitly expressing > the case distinction for the handling of expressions. > > Adjusted transformation rule: > @@ > type T; > T* dst_ptr, src_ptr; > T[] dst_arr, src_arr; > expression n, x; > @@ > -memcpy > +COPY_ARRAY > ( > ( dst_ptr > | dst_arr > ) > , > ( src_ptr > | src_arr > ) > , > - (n) * \( sizeof(T) \| sizeof(*(x)) \) > + n > ) > > > Regards, > Markus > _______________________________________________ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci >