[PATCH 4/5] config: return an empty list, not NULL
- From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Sep 27, 2022, 14:08 UTC
- Message-ID
- <396343ce7dd17f86bbbc66197c6f0b4012caf445.1664287711.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1369.git.1664287711.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>
For the multi-valued config API methods, Git previously returned a NULL list instead of an empty list. Previous changes adjusted all callers to instead expect an empty, non-NULL list, making this a safe change.
The next change will remove the NULL checks from all callers.
Signed-off-by: Derrick Stolee <derrickstolee@github.com> --- config.c | 3 ++- config.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/config.c b/config.c index 0c41606c7d4..2d4ca1ae6dc 100644 --- a/config.c +++ b/config.c @@ -2415,8 +2415,9 @@ int git_configset_get_value(struct config_set *cs, const char *key, const char * const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key) { + static struct string_list empty_list = STRING_LIST_INIT_NODUP; struct config_set_element *e = configset_find_element(cs, key); - return e ? &e->value_list : NULL; + return e ? &e->value_list : &empty_list; } int git_configset_get_string(struct config_set *cs, const char *key, char **dest) diff --git a/config.h b/config.h index ca994d77147..9897b97c0b9 100644 --- a/config.h +++ b/config.h @@ -458,7 +458,7 @@ int git_configset_add_parameters(struct config_set *cs); /** * Finds and returns the value list, sorted in order of increasing priority * for the configuration variable `key` and config set `cs`. When the - * configuration variable `key` is not found, returns NULL. The caller + * configuration variable `key` is not found, returns an empty list. The caller * should not free or modify the returned pointer, as it is owned by the cache. */ const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); @@ -543,8 +543,8 @@ int git_config_get_value(const char *key, const char **value); /** * Finds and returns the value list, sorted in order of increasing priority * for the configuration variable `key`. When the configuration variable - * `key` is not found, returns NULL. The caller should not free or modify - * the returned pointer, as it is owned by the cache. + * `key` is not found, returns an empty list. The caller should not free or + * modify the returned pointer, as it is owned by the cache. */ const struct string_list *git_config_get_value_multi(const char *key);
-- gitgitgadget