*.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
In C it isn't required to specify that all members of a struct are zero'd out to 0, NULL or '\0', just providing a "{ 0 }" will accomplish that. Let's also change code that provided N zero'd fields to just provide one, and change e.g. "{ NULL }" to "{ 0 }" for consistency. I.e. even if the first member is a pointer let's use "0" instead of "NULL". The point of using "0" consistently is to pick one, and to not have the reader wonder why we're not using the same pattern everywhere. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Sep 27, 2021 at 14:54 UTC
9865b6e6a4ca1e895fd473c827cf1822f3bd8249
13 files changed
+21
-24
builtin/submodule--helper.c
+8
-8
@@ -307,7 +307,7 @@ struct module_list {
307
const struct cache_entry **entries;
308
int alloc, nr;
309
};
310
-#define MODULE_LIST_INIT { NULL, 0, 0 }
310
+#define MODULE_LIST_INIT { 0 }
311
312
static int module_list_compute(int argc, const char **argv,
313
const char *prefix,
@@ -588,7 +588,7 @@ struct init_cb {
588
const char *prefix;
589
unsigned int flags;
590
};
591
-#define INIT_CB_INIT { NULL, 0 }
591
+#define INIT_CB_INIT { 0 }
592
593
static void init_submodule(const char *path, const char *prefix,
594
unsigned int flags)
@@ -717,7 +717,7 @@ struct status_cb {
717
const char *prefix;
718
unsigned int flags;
719
};
720
-#define STATUS_CB_INIT { NULL, 0 }
720
+#define STATUS_CB_INIT { 0 }
721
722
static void print_status(unsigned int flags, char state, const char *path,
723
const struct object_id *oid, const char *displaypath)
@@ -911,13 +911,13 @@ struct module_cb {
911
char status;
912
const char *sm_path;
913
};
914
-#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
914
+#define MODULE_CB_INIT { 0 }
915
916
struct module_cb_list {
917
struct module_cb **entries;
918
int alloc, nr;
919
};
920
-#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
920
+#define MODULE_CB_LIST_INIT { 0 }
921
922
struct summary_cb {
923
int argc;
@@ -928,7 +928,7 @@ struct summary_cb {
928
unsigned int files: 1;
929
int summary_limit;
930
};
931
-#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
931
+#define SUMMARY_CB_INIT { 0 }
932
933
enum diff_cmd {
934
DIFF_INDEX,
@@ -1334,7 +1334,7 @@ struct sync_cb {
1334
const char *prefix;
1335
unsigned int flags;
1336
};
1337
-#define SYNC_CB_INIT { NULL, 0 }
1337
+#define SYNC_CB_INIT { 0 }
1338
1339
static void sync_submodule(const char *path, const char *prefix,
1340
unsigned int flags)
@@ -1480,7 +1480,7 @@ struct deinit_cb {
1480
const char *prefix;
1481
unsigned int flags;
1482
};
1483
-#define DEINIT_CB_INIT { NULL, 0 }
1483
+#define DEINIT_CB_INIT { 0 }
1484
1485
static void deinit_submodule(const char *path, const char *prefix,
1486
unsigned int flags)
checkout.c
+1
-1
@@ -14,7 +14,7 @@ struct tracking_name_data {
14
struct object_id *default_dst_oid;
15
};
16
17
-#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
17
+#define TRACKING_NAME_DATA_INIT { 0 }
18
19
static int check_tracking_name(struct remote *remote, void *cb_data)
20
{
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+1
-1
@@ -138,7 +138,7 @@ struct credential {
138
char *password;
139
};
140
141
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
141
+#define CREDENTIAL_INIT { 0 }
142
143
typedef int (*credential_op_cb)(struct credential *);
144
contrib/credential/libsecret/git-credential-libsecret.c
+1
-1
@@ -41,7 +41,7 @@ struct credential {
41
char *password;
42
};
43
44
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
44
+#define CREDENTIAL_INIT { 0 }
45
46
typedef int (*credential_op_cb)(struct credential *);
47
diff.c
+2
-2
@@ -775,13 +775,13 @@ struct emitted_diff_symbol {
775
int indent_width; /* The visual width of the indentation */
776
enum diff_symbol s;
777
};
778
-#define EMITTED_DIFF_SYMBOL_INIT {NULL}
778
+#define EMITTED_DIFF_SYMBOL_INIT { 0 }
779
780
struct emitted_diff_symbols {
781
struct emitted_diff_symbol *buf;
782
int nr, alloc;
783
};
784
-#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
784
+#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
785
786
static void append_emitted_diff_symbol(struct diff_options *o,
787
struct emitted_diff_symbol *e)
lockfile.h
+1
-1
@@ -121,7 +121,7 @@ struct lock_file {
121
struct tempfile *tempfile;
122
};
123
124
-#define LOCK_INIT { NULL }
124
+#define LOCK_INIT { 0 }
125
126
/* String appended to a filename to derive the lockfile name: */
127
#define LOCK_SUFFIX ".lock"
object-store.h
+1
-1
@@ -371,7 +371,7 @@ struct object_info {
371
* Initializer for a "struct object_info" that wants no items. You may
372
* also memset() the memory to all-zeroes.
373
*/
374
-#define OBJECT_INFO_INIT {NULL}
374
+#define OBJECT_INFO_INIT { 0 }
375
376
/* Invoke lookup_replace_object() on the given hash */
377
#define OBJECT_INFO_LOOKUP_REPLACE 1
object.h
+1
-1
@@ -55,7 +55,7 @@ struct object_array {
55
} *objects;
56
};
57
58
-#define OBJECT_ARRAY_INIT { 0, 0, NULL }
58
+#define OBJECT_ARRAY_INIT { 0 }
59
60
/*
61
* object flag allocation:
oid-array.h
+1
-1
@@ -56,7 +56,7 @@ struct oid_array {
56
int sorted;
57
};
58
59
-#define OID_ARRAY_INIT { NULL, 0, 0, 0 }
59
+#define OID_ARRAY_INIT { 0 }
60
61
/**
62
* Add an item to the set. The object ID will be placed at the end of the array
path.h
+1
-4
@@ -181,10 +181,7 @@ struct path_cache {
181
const char *shallow;
182
};
183
184
-#define PATH_CACHE_INIT \
185
- { \
186
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
187
- }
184
+#define PATH_CACHE_INIT { 0 }
185
186
const char *git_path_squash_msg(struct repository *r);
187
const char *git_path_merge_msg(struct repository *r);
ref-filter.c
+1
-1
@@ -633,7 +633,7 @@ static struct {
633
*/
634
};
635
636
-#define REF_FORMATTING_STATE_INIT { 0, NULL }
636
+#define REF_FORMATTING_STATE_INIT { 0 }
637
638
struct ref_formatting_stack {
639
struct ref_formatting_stack *prev;
remote.c
+1
-1
@@ -2403,7 +2403,7 @@ struct reflog_commit_array {
2403
size_t nr, alloc;
2404
};
2405
2406
-#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }
2406
+#define REFLOG_COMMIT_ARRAY_INIT { 0 }
2407
2408
/* Append a commit to the array. */
2409
static void append_commit(struct reflog_commit_array *arr,
revision.c
+1
-1
@@ -249,7 +249,7 @@ struct commit_stack {
249
struct commit **items;
250
size_t nr, alloc;
251
};
252
-#define COMMIT_STACK_INIT { NULL, 0, 0 }
252
+#define COMMIT_STACK_INIT { 0 }
253
254
static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
255
{