Merge branch 'rs/copy-array' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:15 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:15 +0000 (12:38 -0700)
Code clean-up.

* rs/copy-array:
use COPY_ARRAY for copying arrays
coccinelle: use COPY_ARRAY for copying arrays

1  2 
kwset.c
packfile.c
diff --combined kwset.c
index efc2ff41bc361a7a3bf940b04642ccba8538cb3b,090ffcafa2bd0eeff8bbc08ea15867fe8f5b7890..fc439e0667f137f3449635a37a32f8418d5041f0
+++ b/kwset.c
  #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 d786ec731202e5d623a7558bec2168194db11514,2ff570fbfdb2fc0e7f2cbc7bb8d1f25cb7b402bd..d55cb7f013f2c28cea7245c09eb0c334ef10511a
@@@ -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);
                }