From: Yu Watanabe Date: Thu, 7 Sep 2023 19:59:39 +0000 (+0900) Subject: conf-parser: modernize config_section_new() X-Git-Tag: v255-rc1~548^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08ca764d0ae82651508e010c4f2e762e3edb92b0;p=thirdparty%2Fsystemd.git conf-parser: modernize config_section_new() - add assertions, - rename argument to store result. --- 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);