diff options
author | Sebastian Leske <sebastian.leske@sleske.name> | 2015-09-11 18:41:26 +0200 |
---|---|---|
committer | Sebastian Leske <sebastian.leske@sleske.name> | 2015-09-13 14:10:01 +0200 |
commit | 6558a05c70330c6566ad8c181bec35baf924f289 (patch) | |
tree | df09d46b1e7d914f5d55722b6e8ff404325f26ef /navit/attr.c | |
parent | f7c86cf0ba50fff0e7454058af231e0f27d522d2 (diff) | |
download | navit-6558a05c70330c6566ad8c181bec35baf924f289.tar.gz |
Fix:Warn about incorrect values for XML attributes.R6266
Print a warning if an incorrect value is supplied for an XML attribute
which expects a numeric or boolean value.
The old code silently defaulted to 0 and true respectively.
Diffstat (limited to 'navit/attr.c')
-rw-r--r-- | navit/attr.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/navit/attr.c b/navit/attr.c index d6a47a36f..7b7e1376b 100644 --- a/navit/attr.c +++ b/navit/attr.c @@ -222,13 +222,18 @@ attr_new_from_text(const char *name, const char *value) ret->u.str=g_strdup(value); break; } - if (attr >= attr_type_int_begin && attr <= attr_type_int_end) { + if (attr >= attr_type_int_begin && attr < attr_type_boolean_begin) { + char *tail; if (value[0] == '0' && value[1] == 'x') - ret->u.num=strtoul(value, NULL, 0); + ret->u.num=strtoul(value, &tail, 0); else - ret->u.num=strtol(value, NULL, 0); + ret->u.num=strtol(value, &tail, 0); + if (*tail) { + dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a number. " + "Defaulting to 0.\n", value, name); + } - if ((attr >= attr_type_rel_abs_begin) && (attr < attr_type_boolean_begin)) { + if (attr >= attr_type_rel_abs_begin) { /* Absolute values are from -0x40000000 - 0x40000000, with 0x0 being 0 (who would have thought that?) Relative values are from 0x40000001 - 0x80000000, with 0x60000000 being 0 */ if (strchr(value, '%')) { @@ -242,11 +247,18 @@ attr_new_from_text(const char *name, const char *value) dbg(lvl_error, "Non-relative possibly-relative attribute with invalid value %li\n", ret->u.num); } } - } else if (attr >= attr_type_boolean_begin) { // also check for yes and no - if (g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false")) - ret->u.num=1; - else - ret->u.num=0; + } + break; + } + if (attr >= attr_type_boolean_begin && attr <= attr_type_int_end) { + if (!(g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false"))) + ret->u.num=0; + else if (!(g_ascii_strcasecmp(value,"yes") && g_ascii_strcasecmp(value,"1") && g_ascii_strcasecmp(value,"true"))) + ret->u.num=1; + else { + dbg(lvl_error, "Incorrect value '%s' for attribute '%s'; expected a boolean (no/0/false or yes/1/true). " + "Defaulting to 'true'.\n", value, name); + ret->u.num=1; } break; } @@ -278,7 +290,7 @@ attr_new_from_text(const char *name, const char *value) transform_to_geo(projection_mg, &c, g); break; } - dbg(lvl_debug,"default\n"); + dbg(lvl_debug,"unknown attribute\n"); g_free(ret); ret=NULL; } |