From 54e17719d64ecfae66216837bc19c73930f5d560 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 2 Jun 2023 17:00:45 -0700 Subject: 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. --- src/til_settings.c | 7 +++++-- 1 file 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); } -- cgit v1.2.3