cfg: Fix behavior of cfg_get(0, "a") when a key "a.b" exists.
authorBen Pfaff <blp@nicira.com>
Thu, 5 Mar 2009 19:13:49 +0000 (11:13 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 5 Mar 2009 19:13:49 +0000 (11:13 -0800)
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()).

lib/cfg.c

index 8aa420d3088c2546efb21a1caa8cbdca090a744a..1fba0a173a300eda67bcef67220930817960926f 100644 (file)
--- a/lib/cfg.c
+++ b/lib/cfg.c
 #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++;