From: Junio C Hamano Date: Mon, 29 Jul 2019 19:38:15 +0000 (-0700) Subject: Merge branch 'rs/copy-array' into maint X-Git-Tag: v2.23.0-rc0~1^2~24 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/90334a8497f3637876806deb159c4d9c39a7899b?hp=-c Merge branch 'rs/copy-array' into maint Code clean-up. * rs/copy-array: use COPY_ARRAY for copying arrays coccinelle: use COPY_ARRAY for copying arrays --- 90334a8497f3637876806deb159c4d9c39a7899b diff --combined kwset.c index efc2ff41bc,090ffcafa2..fc439e0667 --- a/kwset.c +++ b/kwset.c @@@ -38,13 -38,7 +38,13 @@@ #include "compat/obstack.h" #define NCHAR (UCHAR_MAX + 1) -#define obstack_chunk_alloc xmalloc +/* adapter for `xmalloc()`, which takes `size_t`, not `long` */ +static void *obstack_chunk_alloc(long size) +{ + if (size < 0) + BUG("Cannot allocate a negative amount: %ld", size); + return xmalloc(size); +} #define obstack_chunk_free free #define U(c) ((unsigned char) (c)) @@@ -481,7 -475,7 +481,7 @@@ kwsprep (kwset_t kws for (i = 0; i < NCHAR; ++i) kwset->next[i] = next[U(trans[i])]; else - memcpy(kwset->next, next, NCHAR * sizeof(struct trie *)); + COPY_ARRAY(kwset->next, next, NCHAR); } /* Fix things up for any translation table. */ diff --combined packfile.c index d786ec7312,2ff570fbfd..d55cb7f013 --- a/packfile.c +++ b/packfile.c @@@ -640,7 -640,7 +640,7 @@@ unsigned char *use_pack(struct packed_g while (packed_git_limit < pack_mapped && unuse_one_window(p)) ; /* nothing */ - win->base = xmmap(NULL, win->len, + win->base = xmmap_gently(NULL, win->len, PROT_READ, MAP_PRIVATE, p->pack_fd, win->offset); if (win->base == MAP_FAILED) @@@ -1269,7 -1269,7 +1269,7 @@@ static enum object_type packed_to_objec if (poi_stack_nr >= poi_stack_alloc && poi_stack == small_poi_stack) { poi_stack_alloc = alloc_nr(poi_stack_nr); ALLOC_ARRAY(poi_stack, poi_stack_alloc); - memcpy(poi_stack, small_poi_stack, sizeof(off_t)*poi_stack_nr); + COPY_ARRAY(poi_stack, small_poi_stack, poi_stack_nr); } else { ALLOC_GROW(poi_stack, poi_stack_nr+1, poi_stack_alloc); } @@@ -1679,8 -1679,8 +1679,8 @@@ void *unpack_entry(struct repository *r && delta_stack == small_delta_stack) { delta_stack_alloc = alloc_nr(delta_stack_nr); ALLOC_ARRAY(delta_stack, delta_stack_alloc); - memcpy(delta_stack, small_delta_stack, - sizeof(*delta_stack)*delta_stack_nr); + COPY_ARRAY(delta_stack, small_delta_stack, + delta_stack_nr); } else { ALLOC_GROW(delta_stack, delta_stack_nr+1, delta_stack_alloc); }