Skip to content

Commit 9865b6e

Browse files
avargitster
authored andcommitted
*.[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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d444d9 commit 9865b6e

File tree

13 files changed

+21
-24
lines changed

13 files changed

+21
-24
lines changed

builtin/submodule--helper.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct module_list {
307307
const struct cache_entry **entries;
308308
int alloc, nr;
309309
};
310-
#define MODULE_LIST_INIT { NULL, 0, 0 }
310+
#define MODULE_LIST_INIT { 0 }
311311

312312
static int module_list_compute(int argc, const char **argv,
313313
const char *prefix,
@@ -588,7 +588,7 @@ struct init_cb {
588588
const char *prefix;
589589
unsigned int flags;
590590
};
591-
#define INIT_CB_INIT { NULL, 0 }
591+
#define INIT_CB_INIT { 0 }
592592

593593
static void init_submodule(const char *path, const char *prefix,
594594
unsigned int flags)
@@ -717,7 +717,7 @@ struct status_cb {
717717
const char *prefix;
718718
unsigned int flags;
719719
};
720-
#define STATUS_CB_INIT { NULL, 0 }
720+
#define STATUS_CB_INIT { 0 }
721721

722722
static void print_status(unsigned int flags, char state, const char *path,
723723
const struct object_id *oid, const char *displaypath)
@@ -911,13 +911,13 @@ struct module_cb {
911911
char status;
912912
const char *sm_path;
913913
};
914-
#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
914+
#define MODULE_CB_INIT { 0 }
915915

916916
struct module_cb_list {
917917
struct module_cb **entries;
918918
int alloc, nr;
919919
};
920-
#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
920+
#define MODULE_CB_LIST_INIT { 0 }
921921

922922
struct summary_cb {
923923
int argc;
@@ -928,7 +928,7 @@ struct summary_cb {
928928
unsigned int files: 1;
929929
int summary_limit;
930930
};
931-
#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
931+
#define SUMMARY_CB_INIT { 0 }
932932

933933
enum diff_cmd {
934934
DIFF_INDEX,
@@ -1334,7 +1334,7 @@ struct sync_cb {
13341334
const char *prefix;
13351335
unsigned int flags;
13361336
};
1337-
#define SYNC_CB_INIT { NULL, 0 }
1337+
#define SYNC_CB_INIT { 0 }
13381338

13391339
static void sync_submodule(const char *path, const char *prefix,
13401340
unsigned int flags)
@@ -1480,7 +1480,7 @@ struct deinit_cb {
14801480
const char *prefix;
14811481
unsigned int flags;
14821482
};
1483-
#define DEINIT_CB_INIT { NULL, 0 }
1483+
#define DEINIT_CB_INIT { 0 }
14841484

14851485
static void deinit_submodule(const char *path, const char *prefix,
14861486
unsigned int flags)

checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct tracking_name_data {
1414
struct object_id *default_dst_oid;
1515
};
1616

17-
#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
17+
#define TRACKING_NAME_DATA_INIT { 0 }
1818

1919
static int check_tracking_name(struct remote *remote, void *cb_data)
2020
{

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct credential {
138138
char *password;
139139
};
140140

141-
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
141+
#define CREDENTIAL_INIT { 0 }
142142

143143
typedef int (*credential_op_cb)(struct credential *);
144144

contrib/credential/libsecret/git-credential-libsecret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct credential {
4141
char *password;
4242
};
4343

44-
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
44+
#define CREDENTIAL_INIT { 0 }
4545

4646
typedef int (*credential_op_cb)(struct credential *);
4747

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,13 @@ struct emitted_diff_symbol {
775775
int indent_width; /* The visual width of the indentation */
776776
enum diff_symbol s;
777777
};
778-
#define EMITTED_DIFF_SYMBOL_INIT {NULL}
778+
#define EMITTED_DIFF_SYMBOL_INIT { 0 }
779779

780780
struct emitted_diff_symbols {
781781
struct emitted_diff_symbol *buf;
782782
int nr, alloc;
783783
};
784-
#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
784+
#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
785785

786786
static void append_emitted_diff_symbol(struct diff_options *o,
787787
struct emitted_diff_symbol *e)

lockfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct lock_file {
121121
struct tempfile *tempfile;
122122
};
123123

124-
#define LOCK_INIT { NULL }
124+
#define LOCK_INIT { 0 }
125125

126126
/* String appended to a filename to derive the lockfile name: */
127127
#define LOCK_SUFFIX ".lock"

object-store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct object_info {
371371
* Initializer for a "struct object_info" that wants no items. You may
372372
* also memset() the memory to all-zeroes.
373373
*/
374-
#define OBJECT_INFO_INIT {NULL}
374+
#define OBJECT_INFO_INIT { 0 }
375375

376376
/* Invoke lookup_replace_object() on the given hash */
377377
#define OBJECT_INFO_LOOKUP_REPLACE 1

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct object_array {
5555
} *objects;
5656
};
5757

58-
#define OBJECT_ARRAY_INIT { 0, 0, NULL }
58+
#define OBJECT_ARRAY_INIT { 0 }
5959

6060
/*
6161
* object flag allocation:

oid-array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct oid_array {
5656
int sorted;
5757
};
5858

59-
#define OID_ARRAY_INIT { NULL, 0, 0, 0 }
59+
#define OID_ARRAY_INIT { 0 }
6060

6161
/**
6262
* Add an item to the set. The object ID will be placed at the end of the array

path.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ struct path_cache {
181181
const char *shallow;
182182
};
183183

184-
#define PATH_CACHE_INIT \
185-
{ \
186-
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
187-
}
184+
#define PATH_CACHE_INIT { 0 }
188185

189186
const char *git_path_squash_msg(struct repository *r);
190187
const char *git_path_merge_msg(struct repository *r);

0 commit comments

Comments
 (0)