*.[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>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2021-09-27 14:54:25 +02:00 committed by Junio C Hamano
parent 9d444d9ee0
commit 9865b6e6a4
13 changed files with 21 additions and 24 deletions

View File

@ -307,7 +307,7 @@ struct module_list {
const struct cache_entry **entries;
int alloc, nr;
};
#define MODULE_LIST_INIT { NULL, 0, 0 }
#define MODULE_LIST_INIT { 0 }
static int module_list_compute(int argc, const char **argv,
const char *prefix,
@ -588,7 +588,7 @@ struct init_cb {
const char *prefix;
unsigned int flags;
};
#define INIT_CB_INIT { NULL, 0 }
#define INIT_CB_INIT { 0 }
static void init_submodule(const char *path, const char *prefix,
unsigned int flags)
@ -717,7 +717,7 @@ struct status_cb {
const char *prefix;
unsigned int flags;
};
#define STATUS_CB_INIT { NULL, 0 }
#define STATUS_CB_INIT { 0 }
static void print_status(unsigned int flags, char state, const char *path,
const struct object_id *oid, const char *displaypath)
@ -911,13 +911,13 @@ struct module_cb {
char status;
const char *sm_path;
};
#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
#define MODULE_CB_INIT { 0 }
struct module_cb_list {
struct module_cb **entries;
int alloc, nr;
};
#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
#define MODULE_CB_LIST_INIT { 0 }
struct summary_cb {
int argc;
@ -928,7 +928,7 @@ struct summary_cb {
unsigned int files: 1;
int summary_limit;
};
#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
#define SUMMARY_CB_INIT { 0 }
enum diff_cmd {
DIFF_INDEX,
@ -1334,7 +1334,7 @@ struct sync_cb {
const char *prefix;
unsigned int flags;
};
#define SYNC_CB_INIT { NULL, 0 }
#define SYNC_CB_INIT { 0 }
static void sync_submodule(const char *path, const char *prefix,
unsigned int flags)
@ -1480,7 +1480,7 @@ struct deinit_cb {
const char *prefix;
unsigned int flags;
};
#define DEINIT_CB_INIT { NULL, 0 }
#define DEINIT_CB_INIT { 0 }
static void deinit_submodule(const char *path, const char *prefix,
unsigned int flags)

View File

@ -14,7 +14,7 @@ struct tracking_name_data {
struct object_id *default_dst_oid;
};
#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
#define TRACKING_NAME_DATA_INIT { 0 }
static int check_tracking_name(struct remote *remote, void *cb_data)
{

View File

@ -138,7 +138,7 @@ struct credential {
char *password;
};
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);

View File

@ -41,7 +41,7 @@ struct credential {
char *password;
};
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);

4
diff.c
View File

@ -775,13 +775,13 @@ struct emitted_diff_symbol {
int indent_width; /* The visual width of the indentation */
enum diff_symbol s;
};
#define EMITTED_DIFF_SYMBOL_INIT {NULL}
#define EMITTED_DIFF_SYMBOL_INIT { 0 }
struct emitted_diff_symbols {
struct emitted_diff_symbol *buf;
int nr, alloc;
};
#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
static void append_emitted_diff_symbol(struct diff_options *o,
struct emitted_diff_symbol *e)

View File

@ -121,7 +121,7 @@ struct lock_file {
struct tempfile *tempfile;
};
#define LOCK_INIT { NULL }
#define LOCK_INIT { 0 }
/* String appended to a filename to derive the lockfile name: */
#define LOCK_SUFFIX ".lock"

View File

@ -371,7 +371,7 @@ struct object_info {
* Initializer for a "struct object_info" that wants no items. You may
* also memset() the memory to all-zeroes.
*/
#define OBJECT_INFO_INIT {NULL}
#define OBJECT_INFO_INIT { 0 }
/* Invoke lookup_replace_object() on the given hash */
#define OBJECT_INFO_LOOKUP_REPLACE 1

View File

@ -55,7 +55,7 @@ struct object_array {
} *objects;
};
#define OBJECT_ARRAY_INIT { 0, 0, NULL }
#define OBJECT_ARRAY_INIT { 0 }
/*
* object flag allocation:

View File

@ -56,7 +56,7 @@ struct oid_array {
int sorted;
};
#define OID_ARRAY_INIT { NULL, 0, 0, 0 }
#define OID_ARRAY_INIT { 0 }
/**
* Add an item to the set. The object ID will be placed at the end of the array

5
path.h
View File

@ -181,10 +181,7 @@ struct path_cache {
const char *shallow;
};
#define PATH_CACHE_INIT \
{ \
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
}
#define PATH_CACHE_INIT { 0 }
const char *git_path_squash_msg(struct repository *r);
const char *git_path_merge_msg(struct repository *r);

View File

@ -633,7 +633,7 @@ static struct {
*/
};
#define REF_FORMATTING_STATE_INIT { 0, NULL }
#define REF_FORMATTING_STATE_INIT { 0 }
struct ref_formatting_stack {
struct ref_formatting_stack *prev;

View File

@ -2403,7 +2403,7 @@ struct reflog_commit_array {
size_t nr, alloc;
};
#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }
#define REFLOG_COMMIT_ARRAY_INIT { 0 }
/* Append a commit to the array. */
static void append_commit(struct reflog_commit_array *arr,

View File

@ -249,7 +249,7 @@ struct commit_stack {
struct commit **items;
size_t nr, alloc;
};
#define COMMIT_STACK_INIT { NULL, 0, 0 }
#define COMMIT_STACK_INIT { 0 }
static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
{