diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-06-02 17:00:45 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-06-03 07:42:02 -0700 |
commit | 54e17719d64ecfae66216837bc19c73930f5d560 (patch) | |
tree | 657218340797e739f881a2542c09f099cee20cc8 | |
parent | a390e8201cbc0e5b71684f85f56b05d43da399e9 (diff) |
til_settings: require value in til_settings_add_value()
There doesn't seem to be a use case for inserting NULL-value
settings, and it's ergonomic to assume a til_setting_t.value is
always a non-NULL heap-allocated string.
-rw-r--r-- | src/til_settings.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/til_settings.c b/src/til_settings.c index 510dbaf..08098d5 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -295,15 +295,18 @@ int til_settings_get_and_describe_value(const til_settings_t *settings, const ti /* add key,value as a new setting to settings, - * NULL keys and/or values are passed through as-is + * NULL keys are passed through as-is + * values must not be NULL * desc may be NULL, it's simply passed along as a passenger. */ /* returns the added setting, or NULL on error (ENOMEM) */ til_setting_t * til_settings_add_value(til_settings_t *settings, const char *key, const char *value, const til_setting_desc_t *desc) { assert(settings); + assert(value); + /* XXX: ^^ non-NULL values makes til_settings_get_value_by_idx() NULL-return-for-end-of-settings OK */ - return add_setting(settings, key ? strdup(key) : NULL, value ? strdup(value) : NULL, desc); + return add_setting(settings, key ? strdup(key) : NULL, strdup(value), desc); } |