Index: xmlschemastypes.c =================================================================== RCS file: /cvs/gnome/libxml2/xmlschemastypes.c,v retrieving revision 1.52 diff -c -r1.52 xmlschemastypes.c *** xmlschemastypes.c 25 Mar 2004 09:35:49 -0000 1.52 --- xmlschemastypes.c 29 May 2004 14:48:29 -0000 *************** *** 2608,2627 **** #define MODULO_RANGE(a,low,high) ((MODULO((a-low),(high-low)))+low) /** * _xmlSchemaDateAdd: * @dt: an #xmlSchemaValPtr * @dur: an #xmlSchemaValPtr of type #XS_DURATION * * Compute a new date/time from @dt and @dur. This function assumes @dt * is either #XML_SCHEMAS_DATETIME, #XML_SCHEMAS_DATE, #XML_SCHEMAS_GYEARMONTH, ! * or #XML_SCHEMAS_GYEAR. * ! * Returns date/time pointer or NULL. */ static xmlSchemaValPtr _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur) { ! xmlSchemaValPtr ret; long carry, tempdays, temp; xmlSchemaValDatePtr r, d; xmlSchemaValDurationPtr u; --- 2608,2648 ---- #define MODULO_RANGE(a,low,high) ((MODULO((a-low),(high-low)))+low) /** + * xmlSchemaDupVal: + * @v: the #xmlSchemaValPtr value to duplicate + * + * Makes a copy of @v. The calling program is responsible for freeing + * the returned value. + * + * returns a pointer to a duplicated #xmlSchemaValPtr or NULL if error. + */ + static xmlSchemaValPtr + xmlSchemaDupVal (xmlSchemaValPtr v) + { + xmlSchemaValPtr ret = xmlSchemaNewValue(v->type); + if (ret == NULL) + return NULL; + + memcpy(ret, v, sizeof(xmlSchemaVal)); + return ret; + } + + /** * _xmlSchemaDateAdd: * @dt: an #xmlSchemaValPtr * @dur: an #xmlSchemaValPtr of type #XS_DURATION * * Compute a new date/time from @dt and @dur. This function assumes @dt * is either #XML_SCHEMAS_DATETIME, #XML_SCHEMAS_DATE, #XML_SCHEMAS_GYEARMONTH, ! * or #XML_SCHEMAS_GYEAR. The returned #xmlSchemaVal is the same type as ! * @dt. The calling program is responsible for freeing the returned value. * ! * Returns a pointer to a new #xmlSchemaVal or NULL if error. */ static xmlSchemaValPtr _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur) { ! xmlSchemaValPtr ret, tmp; long carry, tempdays, temp; xmlSchemaValDatePtr r, d; xmlSchemaValDurationPtr u; *************** *** 2633,2640 **** if (ret == NULL) return NULL; r = &(ret->value.date); ! d = &(dt->value.date); u = &(dur->value.dur); /* normalization */ --- 2654,2668 ---- if (ret == NULL) return NULL; + /* make a copy so we don't alter the original value */ + tmp = xmlSchemaDupVal(dt); + if (tmp == NULL) { + xmlSchemaFreeValue(ret); + return NULL; + } + r = &(ret->value.date); ! d = &(tmp->value.date); u = &(dur->value.dur); /* normalization */ *************** *** 2740,2771 **** } } ! return ret; ! } - /** - * xmlSchemaDupVal: - * @v: value to duplicate - * - * returns a duplicated value. - */ - static xmlSchemaValPtr - xmlSchemaDupVal (xmlSchemaValPtr v) - { - xmlSchemaValPtr ret = xmlSchemaNewValue(v->type); - if (ret == NULL) - return ret; - - memcpy(ret, v, sizeof(xmlSchemaVal)); return ret; } /** * xmlSchemaDateNormalize: ! * @dt: an #xmlSchemaValPtr * ! * Normalize @dt to GMT time. * */ static xmlSchemaValPtr xmlSchemaDateNormalize (xmlSchemaValPtr dt, double offset) --- 2768,2787 ---- } } ! xmlSchemaFreeValue(tmp); return ret; } /** * xmlSchemaDateNormalize: ! * @dt: an #xmlSchemaValPtr of a date/time type value. ! * @offset: number of seconds to adjust @dt by. * ! * Normalize @dt to GMT time. The @offset parameter is subtracted from ! * the return value is a time-zone offset is present on @dt. * + * Returns a normalized copy of @dt or NULL if error. */ static xmlSchemaValPtr xmlSchemaDateNormalize (xmlSchemaValPtr dt, double offset)