GNOME Bugzilla – Bug 309338
xmlSchemaValDecimal fractions, compare doesn't work
Last modified: 2009-08-15 18:40:50 UTC
I found funny bug in algorithms for decimal numbers. It is error which appears with this validation error: Element '{http://asdf.com}Test': [facet 'minInclusive'] The value '2000.00' is less than the minimum value allowed ('0.00'). Function xmlSchemaValAtomicType has part for decimal number parser, it has the next lines: /* * If a mixed decimal, get rid of trailing zeroes */ if (dec != -1) { while ((cptr > cval) && (*(cptr-1) == '0')) { cptr--; len--; } } and later: } else { v->value.decimal.frac = len - dec; v->value.decimal.total = len; If string to parse contains number likes "2000.00", the 'len' will be less than 'dec'. And as result 'frac' will be big positive number, which will be great than 'total'. In this case comparation with e.g. zero will work wrong, because comparation code tries to compare number of integral digits: integx = x->value.decimal.total - x->value.decimal.frac; integy = y->value.decimal.total - y->value.decimal.frac; The simplest way to avoid the problem is to declare 'frac' structure member as signed integer: struct _xmlSchemaValDecimal { /* would use long long but not portable */ unsigned long lo; unsigned long mi; unsigned long hi; unsigned int extra; unsigned int sign:1; int frac:7; unsigned int total:8; };
Sorry, had no time to look at it yet. Can you privide a test case? I.e. a schema and an instance?
OK, fixed in xmlschemastypes.c revision 1.97. changed to: while ((len > dec) && (cptr > cval) && (*(cptr-1) == '0')) { which will ensure @len never to be less than the number of digits in the integer part of the value. Thanks for the report! I added a regression test for this bug, so no need to provide a test case anymore.
This should be closed by release of libxml2-2.6.21, thanks, Daniel