Commit 584a87a0 authored by Mark Lindner's avatar Mark Lindner

Don't allow add of non-scalar type to array.

parent 728cb836
......@@ -508,6 +508,13 @@ static int __config_vector_checktype(const config_setting_t *vector, int type)
/* ------------------------------------------------------------------------- */
static int __config_type_is_scalar(int type)
{
return((type >= CONFIG_TYPE_INT) && (type <= CONFIG_TYPE_BOOL));
}
/* ------------------------------------------------------------------------- */
static int __config_validate_name(const char *name)
{
const char *p = name;
......@@ -1591,6 +1598,9 @@ config_setting_t *config_setting_add(config_setting_t *parent,
if(! parent)
return(NULL);
if((parent->type == CONFIG_TYPE_ARRAY) && !__config_type_is_scalar(type))
return(NULL); /* only scalars can be added to arrays */
if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST))
name = NULL;
......@@ -1728,3 +1738,9 @@ const char **config_default_include_func(config_t *config,
/* ------------------------------------------------------------------------- */
int config_setting_is_scalar(const config_setting_t *setting)
{
return(__config_type_is_scalar(setting->type));
}
/* ------------------------------------------------------------------------- */
......@@ -234,6 +234,9 @@ extern LIBCONFIG_API const char **config_default_include_func(
config_t *config, const char *include_dir, const char *path,
const char **error);
extern LIBCONFIG_API int config_setting_is_scalar(
const config_setting_t *setting);
#define /* const char * */ config_get_include_dir(/* const config_t * */ C) \
((C)->include_dir)
......@@ -257,10 +260,6 @@ extern LIBCONFIG_API const char **config_default_include_func(
|| ((S)->type == CONFIG_TYPE_INT64) \
|| ((S)->type == CONFIG_TYPE_FLOAT))
#define /* int */ config_setting_is_scalar(/* const config_setting_t * */ S) \
(((S)->type == CONFIG_TYPE_BOOL) || ((S)->type == CONFIG_TYPE_STRING) \
|| config_setting_is_number(S))
#define /* const char * */ config_setting_name( \
/* const config_setting_t * */ S) \
((S)->name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment