After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 309338 - xmlSchemaValDecimal fractions, compare doesn't work
xmlSchemaValDecimal fractions, compare doesn't work
Status: VERIFIED FIXED
Product: libxml2
Classification: Platform
Component: general
2.6.19
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2005-07-02 15:41 UTC by Kupriyanov Anatolij
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Kupriyanov Anatolij 2005-07-02 15:41:00 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;
};
Comment 1 kbuchcik 2005-07-06 11:12:30 UTC
Sorry, had no time to look at it yet. Can you privide a test case? I.e. a schema
and an instance?
Comment 2 kbuchcik 2005-07-06 12:03:58 UTC
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.
Comment 3 Daniel Veillard 2005-09-05 08:58:50 UTC
This should be closed by release of libxml2-2.6.21,

  thanks,

Daniel