summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-09-25 07:15:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-25 23:44:12 (GMT)
commit60566cbb5890abc84fa18c56da70e35ace0b23bf (patch)
treee5d14dd403b88ba2f71baa8800ec878ba23817cb /builtin
parenta63d31b4d3640960d9a71606eee80c32459f906e (diff)
downloadgit-60566cbb5890abc84fa18c56da70e35ace0b23bf.zip
git-60566cbb5890abc84fa18c56da70e35ace0b23bf.tar.gz
git-60566cbb5890abc84fa18c56da70e35ace0b23bf.tar.bz2
add COPY_ARRAY
Add COPY_ARRAY, a safe and convenient helper for copying arrays, complementing ALLOC_ARRAY and REALLOC_ARRAY. Users just specify source, destination and the number of elements; the size of an element is inferred automatically. It checks if the multiplication of size and element count overflows. The inferred size is passed first to st_mult, which allows the division there to be done at compilation time. As a basic type safety check it makes sure the sizes of source and destination elements are the same. That's evaluated at compilation time as well. COPY_ARRAY is safe to use with NULL as source pointer iff 0 elements are to be copied. That convention is used in some cases for initializing arrays. Raw memcpy(3) does not support it -- compilers are allowed to assume that only valid pointers are passed to it and can optimize away NULL checks after such a call. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
0 files changed, 0 insertions, 0 deletions