new file mode 100644
@@ -0,0 +1,8 @@
+@@
+struct string_list *P;
+@@
+- CALLOC_ARRAY(P, 1);
++ ALLOC_ARRAY(P, 1);
+... when != P
+- (P)->strdup_strings = 1;
++ string_list_init_dup(P);
new file mode 100644
@@ -0,0 +1,7 @@
+int init(void)
+{
+ struct string_list *list;
+
+ CALLOC_ARRAY(list, 1);
+ list->strdup_strings = 1;
+}
new file mode 100644
@@ -0,0 +1,7 @@
+int init(void)
+{
+ struct string_list *list;
+
+ ALLOC_ARRAY(list, 1);
+ string_list_init_dup(list);
+}
@@ -1313,8 +1313,8 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
while (len && ref[len - 1] == '/')
ref[--len] = '\0';
if (!hide_refs) {
- CALLOC_ARRAY(hide_refs, 1);
- hide_refs->strdup_strings = 1;
+ ALLOC_ARRAY(hide_refs, 1);
+ string_list_init_dup(hide_refs);
}
string_list_append(hide_refs, ref);
}
@@ -15,8 +15,8 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
return;
if (!istate->resolve_undo) {
- CALLOC_ARRAY(resolve_undo, 1);
- resolve_undo->strdup_strings = 1;
+ ALLOC_ARRAY(resolve_undo, 1);
+ string_list_init_dup(resolve_undo);
istate->resolve_undo = resolve_undo;
}
resolve_undo = istate->resolve_undo;
@@ -57,8 +57,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
int i;
const unsigned rawsz = the_hash_algo->rawsz;
- CALLOC_ARRAY(resolve_undo, 1);
- resolve_undo->strdup_strings = 1;
+ ALLOC_ARRAY(resolve_undo, 1);
+ string_list_init_dup(resolve_undo);
while (size) {
struct string_list_item *lost;
@@ -1578,8 +1578,8 @@ void clear_ref_exclusion(struct string_list **ref_excludes_p)
void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)
{
if (!*ref_excludes_p) {
- CALLOC_ARRAY(*ref_excludes_p, 1);
- (*ref_excludes_p)->strdup_strings = 1;
+ ALLOC_ARRAY(*ref_excludes_p, 1);
+ string_list_init_dup(*ref_excludes_p);
}
string_list_append(*ref_excludes_p, exclude);
}
Add a coccinelle rule to detect a particular misuse of the "struct string_list" API. We have the *_INIT macros, but this code assumed that a zero'd out "struct string_list" with a "strdup_string" set would be the same as string_list_init_dup(). That assumption happens to be right, but let's instead use the helper functions introduced in 183113a5ca9 (string_list: Add STRING_LIST_INIT macro and make use of it., 2010-07-04). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- contrib/coccinelle/string_list.cocci | 8 ++++++++ contrib/coccinelle/tests/string_list.c | 7 +++++++ contrib/coccinelle/tests/string_list.res | 7 +++++++ refs.c | 4 ++-- resolve-undo.c | 8 ++++---- revision.c | 4 ++-- 6 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 contrib/coccinelle/string_list.cocci create mode 100644 contrib/coccinelle/tests/string_list.c create mode 100644 contrib/coccinelle/tests/string_list.res