GNOME Bugzilla – Bug 303670
Schema timezone problem due to unsigned bit field on AIX
Last modified: 2009-08-15 18:40:50 UTC
Distribution/Version: 4.3 On AIX V4.3 using cc_r (AIX Compilers V3.1, level 4.4.0.0 - though I don't think the version's important), configure and compile libxml2 and run the regressions tests. I used the configure options "--enable-shared=no --without-ftp --without-http --without-python --without-modules" but I think the only important one is "--with-schemas", which is on by default. The problem is demonstrated in the Schemas regression tests (by date_0.xsd). The individual test can be run with: ./testSchemas ./test/schemas/date_0.xsd ./test/schemas/date_0.xml I've attached the error messages. The cause of the problem is the use of an 'int' data type for the tzo member (a bitfield) of the _xmlSchemaValDate struct in xmlschemastypes.c. The C standard does not specify whether 'int' data types for bitfields are signed or unsigned - the implementation is free to choose (section 6.7.2.1 of the C standard, according to gcc's documentation). IBM's C compiler makes them unsigned and (it seems that) just about everything else makes them signed. Since tzo is unsigned on AIX the VALID_TZO macro nearly always evaluates to false. The tzo member must be signed (since a time zone can be both positive and negative) so it needs to be marked as signed. The comment in the code indicates that the range of tzo is -1440 to +1440, for which 12 bits is required (not the current 11). I've attached a patch to make both these changes. Note that the same problem occurs in libxslt, in the _exsltDateValDate struct in libexslt/date.c. Also, is there any real reason to use bitfields in these structs? It doesn't save any data space (because of alignment) but adds to the size of the generated code. Wouldn't it be better to use unsigned chars and a short?
Created attachment 46290 [details] [review] proposed patch to xmlschemastypes.c Changes the tzo field of _xmlSchemaValDate to signed and 12 bit
Created attachment 46291 [details] Errors running "testSchemas date_0.xsd date_0.xml"
According to [1], the timezone needs to hold values in the range -840 to +840, since only 14 hours need to be expressed; so only 10 bits needed at least. [1] http://www.w3.org/TR/xmlschema-2/#dateTime-timezones
OK, applied and commited: xmlschemastypes.c revision 1.90. Thanks for the report!
Changed the VALID_TZO macro to restrict the value to be within the range of -840 to 840.
This should be closed by release of libxml2-2.6.21, thanks, Daniel