Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cfg_t *cfg_addtsec(): can't return the pointer to the section if already exists. #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/addsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ int main(void)
/* Add a new section */
sec = cfg_addtsec(cfg, "argument", "two");
cfg_setstr(sec, "value", "foo");
/* Add an existing section */
sec = cfg_addtsec(cfg, "argument", "three");
cfg_setstr(sec, "value", "gazonk!!");
print_message();

cfg_free(cfg);

return 0;

}
6 changes: 4 additions & 2 deletions src/confuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2313,11 +2313,13 @@ DLLIMPORT int cfg_addlist(cfg_t *cfg, const char *name, unsigned int nvalues, ..

DLLIMPORT cfg_t *cfg_addtsec(cfg_t *cfg, const char *name, const char *title)
{
cfg_t *sec;
cfg_opt_t *opt;
cfg_value_t *val;

if (cfg_gettsec(cfg, name, title))
return NULL;
sec = cfg_gettsec(cfg, name, title);
if (sec)
return sec;

opt = cfg_getopt(cfg, name);
if (!opt) {
Expand Down