ubox: Initialize conditionally uninitialized variabled
[project/ubox.git] / validate / validate.c
index 150c08d..e72b811 100644 (file)
@@ -173,8 +173,10 @@ dt_type_list(struct dt_state *s, int nargs)
        char *p, *str = strdup(s->value);
        const char *value = s->value;
 
-       if (!str || !nargs)
+       if (!str || !nargs) {
+               free(str);
                return false;
+       }
 
        for (p = strtok(str, " \t"); p; p = strtok(NULL, " \t"))
        {
@@ -198,7 +200,8 @@ dt_type_list(struct dt_state *s, int nargs)
 static bool
 dt_type_min(struct dt_state *s, int nargs)
 {
-       int n, min;
+       int n;
+       int min = 0;
        char *e;
 
        if (dt_getint(0, min))
@@ -213,7 +216,8 @@ dt_type_min(struct dt_state *s, int nargs)
 static bool
 dt_type_max(struct dt_state *s, int nargs)
 {
-       int n, max;
+       int n;
+       int max = 0;
        char *e;
 
        if (dt_getint(0, max))
@@ -228,7 +232,9 @@ dt_type_max(struct dt_state *s, int nargs)
 static bool
 dt_type_range(struct dt_state *s, int nargs)
 {
-       int n, min, max;
+       int n;
+       int min = 0;
+       int max = 0;
        char *e;
 
        if (dt_getint(0, min) && dt_getint(1, max))
@@ -243,7 +249,7 @@ dt_type_range(struct dt_state *s, int nargs)
 static bool
 dt_type_minlen(struct dt_state *s, int nargs)
 {
-       int min;
+       int min = 0;
 
        if (dt_getint(0, min))
                return (strlen(s->value) >= min);
@@ -254,7 +260,7 @@ dt_type_minlen(struct dt_state *s, int nargs)
 static bool
 dt_type_maxlen(struct dt_state *s, int nargs)
 {
-       int max;
+       int max = 0;
 
        if (dt_getint(0, max))
                return (strlen(s->value) <= max);
@@ -265,7 +271,8 @@ dt_type_maxlen(struct dt_state *s, int nargs)
 static bool
 dt_type_rangelen(struct dt_state *s, int nargs)
 {
-       int min, max;
+       int min = 0;
+       int max = 0;
        int len = strlen(s->value);
 
        if (dt_getint(0, min) && dt_getint(1, max))
@@ -330,8 +337,8 @@ dt_type_bool(struct dt_state *s, int nargs)
 {
        int i;
        const char *values[] = {
-               "0", "off", "false", "no",
-               "1", "on", "true", "yes"
+               "0", "off", "false", "no", "disabled",
+               "1", "on", "true", "yes", "enabled"
        };
 
        for (i = 0; i < sizeof(values) / sizeof(values[0]); i++)
@@ -344,7 +351,8 @@ dt_type_bool(struct dt_state *s, int nargs)
 static bool
 dt_type_string(struct dt_state *s, int nargs)
 {
-       int min, max;
+       int min = 0;
+       int max = 0;
        int len = strlen(s->value);
 
        if (dt_getint(0, min) && (len < min))
@@ -359,7 +367,8 @@ dt_type_string(struct dt_state *s, int nargs)
 static bool
 dt_type_hexstring(struct dt_state *s, int nargs)
 {
-       int min, max;
+       int min = 0;
+       int max = 0;
        int len = strlen(s->value);
        const char *p;
 
@@ -882,50 +891,50 @@ dt_type_uci(struct dt_state *s, int nargs)
 
 
 static struct dt_fun dt_types[] = {
-       { "or",                         DT_INVALID,             dt_type_or                      },
-       { "and",                        DT_INVALID,             dt_type_and                     },
-       { "not",                        DT_INVALID,             dt_type_not                     },
-       { "neg",                        DT_INVALID,             dt_type_neg                     },
-       { "list",                       DT_INVALID,             dt_type_list            },
-       { "min",                        DT_NUMBER,              dt_type_min                     },
-       { "max",                        DT_NUMBER,              dt_type_max                     },
-       { "range",                      DT_NUMBER,              dt_type_range           },
-       { "minlength",          DT_STRING,              dt_type_minlen          },
-       { "maxlength",          DT_STRING,              dt_type_maxlen          },
-       { "rangelength",        DT_STRING,              dt_type_rangelen        },
-       { "integer",            DT_NUMBER,              dt_type_int                     },
-       { "uinteger",           DT_NUMBER,              dt_type_uint            },
-       { "float",                      DT_NUMBER,              dt_type_float           },
-       { "ufloat",                     DT_NUMBER,              dt_type_ufloat          },
-       { "bool",                       DT_BOOL,                dt_type_bool            },
-       { "string",                     DT_STRING,              dt_type_string          },
-       { "hexstring",          DT_STRING,              dt_type_hexstring       },
-       { "ip4addr",            DT_STRING,              dt_type_ip4addr         },
-       { "ip6addr",            DT_STRING,              dt_type_ip6addr         },
-       { "ipaddr",                     DT_STRING,              dt_type_ipaddr          },
-       { "cidr4",                      DT_STRING,              dt_type_cidr4           },
-       { "cidr6",                      DT_STRING,              dt_type_cidr6           },
-       { "cidr",                       DT_STRING,              dt_type_cidr            },
-       { "netmask4",           DT_STRING,              dt_type_netmask4        },
-       { "netmask6",           DT_STRING,              dt_type_netmask6        },
-       { "ipmask4",            DT_STRING,              dt_type_ipmask4         },
-       { "ipmask6",            DT_STRING,              dt_type_ipmask6         },
-       { "ipmask",                     DT_STRING,              dt_type_ipmask          },
-       { "port",                       DT_NUMBER,              dt_type_port            },
-       { "portrange",          DT_STRING,              dt_type_portrange       },
-       { "macaddr",            DT_STRING,              dt_type_macaddr         },
-       { "uciname",            DT_STRING,              dt_type_uciname         },
-       { "wpakey",                     DT_STRING,              dt_type_wpakey          },
-       { "wepkey",                     DT_STRING,              dt_type_wepkey          },
-       { "hostname",           DT_STRING,              dt_type_hostname        },
-       { "host",                       DT_STRING,              dt_type_host            },
-       { "network",            DT_STRING,              dt_type_network         },
-       { "phonedigit",         DT_STRING,              dt_type_phonedigit      },
-       { "directory",          DT_STRING,              dt_type_directory       },
-       { "device",                     DT_STRING,              dt_type_device          },
-       { "file",                       DT_STRING,              dt_type_file            },
-       { "regex",                      DT_STRING,              dt_type_regex           },
-       { "uci",                        DT_STRING,              dt_type_uci                     },
+       { "or",                 DT_INVALID,     dt_type_or              },
+       { "and",                DT_INVALID,     dt_type_and             },
+       { "not",                DT_INVALID,     dt_type_not             },
+       { "neg",                DT_INVALID,     dt_type_neg             },
+       { "list",               DT_INVALID,     dt_type_list            },
+       { "min",                DT_NUMBER,      dt_type_min             },
+       { "max",                DT_NUMBER,      dt_type_max             },
+       { "range",              DT_NUMBER,      dt_type_range           },
+       { "minlength",          DT_STRING,      dt_type_minlen          },
+       { "maxlength",          DT_STRING,      dt_type_maxlen          },
+       { "rangelength",        DT_STRING,      dt_type_rangelen        },
+       { "integer",            DT_NUMBER,      dt_type_int             },
+       { "uinteger",           DT_NUMBER,      dt_type_uint            },
+       { "float",              DT_NUMBER,      dt_type_float           },
+       { "ufloat",             DT_NUMBER,      dt_type_ufloat          },
+       { "bool",               DT_BOOL,        dt_type_bool            },
+       { "string",             DT_STRING,      dt_type_string          },
+       { "hexstring",          DT_STRING,      dt_type_hexstring       },
+       { "ip4addr",            DT_STRING,      dt_type_ip4addr         },
+       { "ip6addr",            DT_STRING,      dt_type_ip6addr         },
+       { "ipaddr",             DT_STRING,      dt_type_ipaddr          },
+       { "cidr4",              DT_STRING,      dt_type_cidr4           },
+       { "cidr6",              DT_STRING,      dt_type_cidr6           },
+       { "cidr",               DT_STRING,      dt_type_cidr            },
+       { "netmask4",           DT_STRING,      dt_type_netmask4        },
+       { "netmask6",           DT_STRING,      dt_type_netmask6        },
+       { "ipmask4",            DT_STRING,      dt_type_ipmask4         },
+       { "ipmask6",            DT_STRING,      dt_type_ipmask6         },
+       { "ipmask",             DT_STRING,      dt_type_ipmask          },
+       { "port",               DT_NUMBER,      dt_type_port            },
+       { "portrange",          DT_STRING,      dt_type_portrange       },
+       { "macaddr",            DT_STRING,      dt_type_macaddr         },
+       { "uciname",            DT_STRING,      dt_type_uciname         },
+       { "wpakey",             DT_STRING,      dt_type_wpakey          },
+       { "wepkey",             DT_STRING,      dt_type_wepkey          },
+       { "hostname",           DT_STRING,      dt_type_hostname        },
+       { "host",               DT_STRING,      dt_type_host            },
+       { "network",            DT_STRING,      dt_type_network         },
+       { "phonedigit",         DT_STRING,      dt_type_phonedigit      },
+       { "directory",          DT_STRING,      dt_type_directory       },
+       { "device",             DT_STRING,      dt_type_device          },
+       { "file",               DT_STRING,      dt_type_file            },
+       { "regex",              DT_STRING,      dt_type_regex           },
+       { "uci",                DT_STRING,      dt_type_uci             },
 
        { }
 };