Skip to content

Commit 6061483

Browse files
To1negitster
authored andcommitted
cocci: extend MEMZERO_ARRAY() rules
Recently the MEMZERO_ARRAY() macro was introduced. In that commit also coccinelle rules were added to capture cases that can be converted to use that macro. Later a few more cases were manually converted to use the macro, but coccinelle didn't capture those. Extend the rules to capture those as well. In various cases the code could be further beautified by removing parentheses which are no longer needed. Modify the coccinelle rules to optimize those as well and fix them. During conversion indentation also used spaces where tabs should be used, fix that in one go. Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit 6061483

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

contrib/coccinelle/array.cocci

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,41 @@ type T;
107107
T *ptr;
108108
expression n;
109109
@@
110-
- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T)
111-
- \| sizeof(*ptr)
112-
- \) )
110+
- memset(ptr, \( 0 \| '\0' \), \( (n) \| n \) * \( sizeof(T)
111+
- \| sizeof(ptr[...])
112+
- \| sizeof(*ptr)
113+
- \) )
114+
+ MEMZERO_ARRAY(ptr, n)
115+
116+
@@
117+
type T;
118+
T *ptr;
119+
expression n;
120+
@@
121+
- memset(ptr, \( 0 \| '\0' \), \( sizeof(T)
122+
- \| sizeof(ptr[...])
123+
- \| sizeof(*ptr)
124+
- \) * \( (n) \| n \) )
125+
+ MEMZERO_ARRAY(ptr, n)
126+
127+
@@
128+
type T;
129+
T[] ptr;
130+
expression n;
131+
@@
132+
- memset(ptr, \( 0 \| '\0' \), \( (n) \| n \) * \( sizeof(T)
133+
- \| sizeof(ptr[...])
134+
- \| sizeof(*ptr)
135+
- \) )
113136
+ MEMZERO_ARRAY(ptr, n)
114137

115138
@@
116139
type T;
117140
T[] ptr;
118141
expression n;
119142
@@
120-
- memset(ptr, \( 0x0 \| 0 \), n * \( sizeof(T)
121-
- \| sizeof(*ptr)
122-
- \) )
143+
- memset(ptr, \( 0 \| '\0' \), \( sizeof(T)
144+
- \| sizeof(ptr[...])
145+
- \| sizeof(*ptr)
146+
- \) * \( (n) \| n \) )
123147
+ MEMZERO_ARRAY(ptr, n)

diffcore-delta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static struct spanhash_top *hash_chars(struct repository *r,
135135
st_mult(sizeof(struct spanhash), (size_t)1 << i)));
136136
hash->alloc_log2 = i;
137137
hash->free = INITIAL_FREE(i);
138-
MEMZERO_ARRAY(hash->data, ((size_t)1 << i));
138+
MEMZERO_ARRAY(hash->data, (size_t)1 << i);
139139

140140
n = 0;
141141
accum1 = accum2 = 0;

ewah/bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void bitmap_grow(struct bitmap *self, size_t word_alloc)
4646
{
4747
size_t old_size = self->word_alloc;
4848
ALLOC_GROW(self->words, word_alloc, self->word_alloc);
49-
MEMZERO_ARRAY(self->words + old_size, (self->word_alloc - old_size));
49+
MEMZERO_ARRAY(self->words + old_size, self->word_alloc - old_size);
5050
}
5151

5252
void bitmap_set(struct bitmap *self, size_t pos)
@@ -192,7 +192,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
192192
self->word_alloc = other_final;
193193
REALLOC_ARRAY(self->words, self->word_alloc);
194194
MEMZERO_ARRAY(self->words + original_size,
195-
(self->word_alloc - original_size));
195+
self->word_alloc - original_size);
196196
}
197197

198198
ewah_iterator_init(&it, other);

0 commit comments

Comments
 (0)