conf-parser: modernize config_section_new()
- add assertions, - rename argument to store result.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user