From a841d3b4cae2e8b0b54a7e89131ebf8617969836 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Mon, 30 Mar 2009 01:08:38 -0700 Subject: [PATCH] Fix skipping of lines when deleting a section with the cfg library. When deleting a section in the "cfg" library, the cfg_del_section function would check each line in the configuration to see if it was part of the section to be deleted. The way it deleted was essentially to move all future lines "down" to replace the line to be deleted. However, it always incremented the pointer to the next entry, which could cause it to skip over other entries that should have been deleted. We now only increment the pointer if we didn't delete a line. --- lib/cfg.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cfg.c b/lib/cfg.c index 0bb50b42..66a5aca5 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -516,9 +516,14 @@ cfg_del_section(const char *section_, ...) ds_put_char(§ion, '.'); va_end(args); - for (p = cfg.names; *p; p++) { /* XXX this is inefficient */ + for (p = cfg.names; *p; ) { /* XXX this is inefficient */ if (!strncmp(section.string, *p, section.length)) { + /* Delete this matching entry in-place, so don't move on to + * the next entry. */ svec_del(&cfg, *p); + } else { + /* Move onto the next entry. */ + p++; } } ds_destroy(§ion); -- 2.30.2