From 08ca764d0ae82651508e010c4f2e762e3edb92b0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 8 Sep 2023 04:59:39 +0900 Subject: [PATCH] conf-parser: modernize config_section_new() - add assertions, - rename argument to store result. --- src/shared/conf-parser.c | 9 ++++++--- src/shared/conf-parser.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 68c4b2ca1af..5476c061d71 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -748,9 +748,13 @@ static int config_section_compare_func(const ConfigSection *x, const ConfigSecti DEFINE_HASH_OPS(config_section_hash_ops, ConfigSection, config_section_hash_func, config_section_compare_func); -int config_section_new(const char *filename, unsigned line, ConfigSection **s) { +int config_section_new(const char *filename, unsigned line, ConfigSection **ret) { ConfigSection *cs; + assert(filename); + assert(line > 0); + assert(ret); + cs = malloc0(offsetof(ConfigSection, filename) + strlen(filename) + 1); if (!cs) return -ENOMEM; @@ -758,8 +762,7 @@ int config_section_new(const char *filename, unsigned line, ConfigSection **s) { strcpy(cs->filename, filename); cs->line = line; - *s = TAKE_PTR(cs); - + *ret = TAKE_PTR(cs); return 0; } diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 902717965cd..3fc434ef03b 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -136,7 +136,7 @@ static inline ConfigSection* config_section_free(ConfigSection *cs) { } DEFINE_TRIVIAL_CLEANUP_FUNC(ConfigSection*, config_section_free); -int config_section_new(const char *filename, unsigned line, ConfigSection **s); +int config_section_new(const char *filename, unsigned line, ConfigSection **ret); extern const struct hash_ops config_section_hash_ops; unsigned hashmap_find_free_section_line(Hashmap *hashmap); -- 2.47.3