From: Ben Pfaff Date: Thu, 5 Mar 2009 19:13:49 +0000 (-0800) Subject: cfg: Fix behavior of cfg_get(0, "a") when a key "a.b" exists. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5a9b6320ba30a836716b049baf1d35bbe6b058c;p=openvswitch cfg: Fix behavior of cfg_get(0, "a") when a key "a.b" exists. The intent of cfg_get_*(0, "a") is to get the first value of a key with the exact name "a", but in the presence of a key with a longer name, e.g. "a.b", it would return the value of that key instead. This file really needs a unit test! I'm really not certain that the fix didn't break other things (e.g. cfg_has_section()). --- diff --git a/lib/cfg.c b/lib/cfg.c index 8aa420d3..1fba0a17 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -44,6 +44,11 @@ #define THIS_MODULE VLM_cfg #include "vlog.h" +/* XXX This file really needs a unit test! For a while, cfg_get_string(0, + * "bridge.a.controller") would return the value of + * "bridge.a.controller.in-band", if it existed, and I'm really not certain + * that the fix didn't break other things (e.g. cfg_has_section()). */ + /* List of configuration files. */ static struct svec cfg_files = SVEC_EMPTY_INITIALIZER; @@ -662,11 +667,11 @@ static int compare_key(const char *a, const char *b) { for (;;) { - int ac = *a == '=' ? '\0' : *a; - int bc = *b == '=' ? '\0' : *b; + int ac = *a == '=' ? INT_MAX : *a; + int bc = *b == '=' ? INT_MAX : *b; if (ac != bc) { return ac < bc ? -1 : 1; - } else if (!ac) { + } else if (ac == INT_MAX) { return 0; } a++;