From: Justin Pettit Date: Mon, 30 Mar 2009 08:08:38 +0000 (-0700) Subject: Fix skipping of lines when deleting a section with the cfg library. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a841d3b4cae2e8b0b54a7e89131ebf8617969836;p=openvswitch 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. --- 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);