Skip to content

Commit a6024d9

Browse files
committed
Merge branch 'rs/copy-array' into pu
* rs/copy-array: use COPY_ARRAY for copying arrays coccinelle: use COPY_ARRAY for copying arrays
2 parents c83cce4 + 921d49b commit a6024d9

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

contrib/coccinelle/array.cocci

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,60 @@
11
@@
2-
type T;
3-
T *dst;
4-
T *src;
5-
expression n;
2+
expression dst, src, n, E;
63
@@
7-
- memcpy(dst, src, (n) * sizeof(*dst));
8-
+ COPY_ARRAY(dst, src, n);
4+
memcpy(dst, src, n * sizeof(
5+
- E[...]
6+
+ *(E)
7+
))
98

109
@@
1110
type T;
12-
T *dst;
13-
T *src;
14-
expression n;
11+
T *ptr;
12+
T[] arr;
13+
expression E, n;
1514
@@
16-
- memcpy(dst, src, (n) * sizeof(*src));
17-
+ COPY_ARRAY(dst, src, n);
15+
(
16+
memcpy(ptr, E,
17+
- n * sizeof(*(ptr))
18+
+ n * sizeof(T)
19+
)
20+
|
21+
memcpy(arr, E,
22+
- n * sizeof(*(arr))
23+
+ n * sizeof(T)
24+
)
25+
|
26+
memcpy(E, ptr,
27+
- n * sizeof(*(ptr))
28+
+ n * sizeof(T)
29+
)
30+
|
31+
memcpy(E, arr,
32+
- n * sizeof(*(arr))
33+
+ n * sizeof(T)
34+
)
35+
)
1836

1937
@@
2038
type T;
21-
T *dst;
22-
T *src;
39+
T *dst_ptr;
40+
T *src_ptr;
41+
T[] dst_arr;
42+
T[] src_arr;
2343
expression n;
2444
@@
25-
- memcpy(dst, src, (n) * sizeof(T));
26-
+ COPY_ARRAY(dst, src, n);
45+
(
46+
- memcpy(dst_ptr, src_ptr, (n) * sizeof(T))
47+
+ COPY_ARRAY(dst_ptr, src_ptr, n)
48+
|
49+
- memcpy(dst_ptr, src_arr, (n) * sizeof(T))
50+
+ COPY_ARRAY(dst_ptr, src_arr, n)
51+
|
52+
- memcpy(dst_arr, src_ptr, (n) * sizeof(T))
53+
+ COPY_ARRAY(dst_arr, src_ptr, n)
54+
|
55+
- memcpy(dst_arr, src_arr, (n) * sizeof(T))
56+
+ COPY_ARRAY(dst_arr, src_arr, n)
57+
)
2758

2859
@@
2960
type T;

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static struct tree_content *grow_tree_content(
644644
struct tree_content *r = new_tree_content(t->entry_count + amt);
645645
r->entry_count = t->entry_count;
646646
r->delta_depth = t->delta_depth;
647-
memcpy(r->entries,t->entries,t->entry_count*sizeof(t->entries[0]));
647+
COPY_ARRAY(r->entries, t->entries, t->entry_count);
648648
release_tree_content(t);
649649
return r;
650650
}

kwset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ kwsprep (kwset_t kws)
481481
for (i = 0; i < NCHAR; ++i)
482482
kwset->next[i] = next[U(trans[i])];
483483
else
484-
memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
484+
COPY_ARRAY(kwset->next, next, NCHAR);
485485
}
486486

487487
/* Fix things up for any translation table. */

packfile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ static enum object_type packed_to_object_type(struct repository *r,
13011301
if (poi_stack_nr >= poi_stack_alloc && poi_stack == small_poi_stack) {
13021302
poi_stack_alloc = alloc_nr(poi_stack_nr);
13031303
ALLOC_ARRAY(poi_stack, poi_stack_alloc);
1304-
memcpy(poi_stack, small_poi_stack, sizeof(off_t)*poi_stack_nr);
1304+
COPY_ARRAY(poi_stack, small_poi_stack, poi_stack_nr);
13051305
} else {
13061306
ALLOC_GROW(poi_stack, poi_stack_nr+1, poi_stack_alloc);
13071307
}
@@ -1711,8 +1711,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
17111711
&& delta_stack == small_delta_stack) {
17121712
delta_stack_alloc = alloc_nr(delta_stack_nr);
17131713
ALLOC_ARRAY(delta_stack, delta_stack_alloc);
1714-
memcpy(delta_stack, small_delta_stack,
1715-
sizeof(*delta_stack)*delta_stack_nr);
1714+
COPY_ARRAY(delta_stack, small_delta_stack,
1715+
delta_stack_nr);
17161716
} else {
17171717
ALLOC_GROW(delta_stack, delta_stack_nr+1, delta_stack_alloc);
17181718
}

pretty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ static void setup_commit_formats(void)
106106
commit_formats_len = ARRAY_SIZE(builtin_formats);
107107
builtin_formats_len = commit_formats_len;
108108
ALLOC_GROW(commit_formats, commit_formats_len, commit_formats_alloc);
109-
memcpy(commit_formats, builtin_formats,
110-
sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
109+
COPY_ARRAY(commit_formats, builtin_formats,
110+
ARRAY_SIZE(builtin_formats));
111111

112112
git_config(git_pretty_formats_config, NULL);
113113
}

0 commit comments

Comments
 (0)