* xmlGetMaxOccurs: * @ctxt: a schema validation context * @node: a subtree containing XML Schema information * * Get the maxOccurs property * * Returns the default if not found, or the value */
| 5963 | * Returns the default if not found, or the value |
| 5964 | */ |
| 5965 | static int |
| 5966 | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 5967 | int min, int max, int def, const char *expected) |
| 5968 | { |
| 5969 | const xmlChar *val, *cur; |
| 5970 | int ret = 0; |
| 5971 | xmlAttrPtr attr; |
| 5972 | |
| 5973 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
| 5974 | if (attr == NULL) |
| 5975 | return (def); |
| 5976 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5977 | if (val == NULL) |
| 5978 | return (def); |
| 5979 | |
| 5980 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
| 5981 | if (max != UNBOUNDED) { |
| 5982 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5983 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5984 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 5985 | NULL, (xmlNodePtr) attr, NULL, expected, |
| 5986 | val, NULL, NULL, NULL); |
| 5987 | return (def); |
| 5988 | } else |
| 5989 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
| 5990 | } |
| 5991 | |
| 5992 | cur = val; |
| 5993 | while (IS_BLANK_CH(*cur)) |
| 5994 | cur++; |
| 5995 | if (*cur == 0) { |
| 5996 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5997 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5998 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 5999 | NULL, (xmlNodePtr) attr, NULL, expected, |
| 6000 | val, NULL, NULL, NULL); |
| 6001 | return (def); |
| 6002 | } |
| 6003 | while ((*cur >= '0') && (*cur <= '9')) { |
| 6004 | if (ret > INT_MAX / 10) { |
| 6005 | ret = INT_MAX; |
| 6006 | } else { |
| 6007 | int digit = *cur - '0'; |
| 6008 | ret *= 10; |
| 6009 | if (ret > INT_MAX - digit) |
| 6010 | ret = INT_MAX; |
| 6011 | else |
| 6012 | ret += digit; |
| 6013 | } |
| 6014 | cur++; |
| 6015 | } |
| 6016 | while (IS_BLANK_CH(*cur)) |
| 6017 | cur++; |
| 6018 | /* |
| 6019 | * TODO: Restrict the maximal value to Integer. |
| 6020 | */ |
| 6021 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 6022 | xmlSchemaPSimpleTypeErr(ctxt, |
no test coverage detected