* xmlSchemaValidateDuration: * @type: the predefined type * @duration: string to analyze * @val: the return computed value * * Check that @duration conforms to the lexical space of the duration type. * if true a value is computed and returned in @val. * * Returns 0 if this validates, a positive error code number otherwise * and -1 in case of internal or API error. */
| 1999 | * and -1 in case of internal or API error. |
| 2000 | */ |
| 2001 | static int |
| 2002 | xmlSchemaValidateDuration (xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
| 2003 | const xmlChar *duration, xmlSchemaValPtr *val, |
| 2004 | int collapse) { |
| 2005 | const xmlChar *cur = duration; |
| 2006 | xmlSchemaValPtr dur; |
| 2007 | int isneg = 0; |
| 2008 | unsigned int seq = 0; |
| 2009 | long days, secs = 0; |
| 2010 | double sec_frac = 0.0; |
| 2011 | |
| 2012 | if (duration == NULL) |
| 2013 | return -1; |
| 2014 | |
| 2015 | if (collapse) |
| 2016 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2017 | |
| 2018 | if (*cur == '-') { |
| 2019 | isneg = 1; |
| 2020 | cur++; |
| 2021 | } |
| 2022 | |
| 2023 | /* duration must start with 'P' (after sign) */ |
| 2024 | if (*cur++ != 'P') |
| 2025 | return 1; |
| 2026 | |
| 2027 | if (*cur == 0) |
| 2028 | return 1; |
| 2029 | |
| 2030 | dur = xmlSchemaNewValue(XML_SCHEMAS_DURATION); |
| 2031 | if (dur == NULL) |
| 2032 | return -1; |
| 2033 | |
| 2034 | while (*cur != 0) { |
| 2035 | long num = 0; |
| 2036 | size_t has_digits = 0; |
| 2037 | int has_frac = 0; |
| 2038 | const xmlChar desig[] = {'Y', 'M', 'D', 'H', 'M', 'S'}; |
| 2039 | |
| 2040 | /* input string should be empty or invalid date/time item */ |
| 2041 | if (seq >= sizeof(desig)) |
| 2042 | goto error; |
| 2043 | |
| 2044 | /* T designator must be present for time items */ |
| 2045 | if (*cur == 'T') { |
| 2046 | if (seq > 3) |
| 2047 | goto error; |
| 2048 | cur++; |
| 2049 | seq = 3; |
| 2050 | } else if (seq == 3) |
| 2051 | goto error; |
| 2052 | |
| 2053 | /* Parse integral part. */ |
| 2054 | while (*cur >= '0' && *cur <= '9') { |
| 2055 | long digit = *cur - '0'; |
| 2056 | |
| 2057 | if (num > LONG_MAX / 10) |
| 2058 | goto error; |
no test coverage detected