diff options
Diffstat (limited to 'src/xml.c')
-rw-r--r-- | src/xml.c | 45 |
1 files changed, 32 insertions, 13 deletions
@@ -222,17 +222,29 @@ cleanup: void lyxml_ns_rm(struct lyxml_ctx *xmlctx) { - for (uint32_t u = xmlctx->ns.count - 1; u + 1 > 0; --u) { - if (((struct lyxml_ns *)xmlctx->ns.objs[u])->depth != xmlctx->elements.count + 1) { + struct lyxml_ns *ns; + uint32_t u; + + if (!xmlctx->ns.count) { + return; + } + + u = xmlctx->ns.count; + do { + --u; + ns = (struct lyxml_ns *)xmlctx->ns.objs[u]; + + if (ns->depth != xmlctx->elements.count + 1) { /* we are done, the namespaces from a single element are supposed to be together */ break; } + /* remove the ns structure */ - free(((struct lyxml_ns *)xmlctx->ns.objs[u])->prefix); - free(((struct lyxml_ns *)xmlctx->ns.objs[u])->uri); - free(xmlctx->ns.objs[u]); + free(ns->prefix); + free(ns->uri); + free(ns); --xmlctx->ns.count; - } + } while (u); if (!xmlctx->ns.count) { /* cleanup the xmlctx's namespaces storage */ @@ -244,9 +256,17 @@ const struct lyxml_ns * lyxml_ns_get(const struct ly_set *ns_set, const char *prefix, size_t prefix_len) { struct lyxml_ns *ns; + uint32_t u; - for (uint32_t u = ns_set->count - 1; u + 1 > 0; --u) { + if (!ns_set->count) { + return NULL; + } + + u = ns_set->count; + do { + --u; ns = (struct lyxml_ns *)ns_set->objs[u]; + if (prefix && prefix_len) { if (ns->prefix && !ly_strncmp(ns->prefix, prefix, prefix_len)) { return ns; @@ -255,7 +275,7 @@ lyxml_ns_get(const struct ly_set *ns_set, const char *prefix, size_t prefix_len) /* default namespace */ return ns; } - } + } while (u); return NULL; } @@ -415,12 +435,11 @@ static LY_ERR lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t *length, ly_bool *ws_only, ly_bool *dynamic) { const struct ly_ctx *ctx = xmlctx->ctx; /* shortcut */ - const char *in = xmlctx->in->current, *start, *in_aux; + const char *in = xmlctx->in->current, *start, *in_aux, *p; char *buf = NULL; size_t offset; /* read offset in input buffer */ size_t len; /* length of the output string (write offset in output buffer) */ size_t size = 0; /* size of the output buffer */ - void *p; uint32_t n; size_t u; ly_bool ws = 1; @@ -467,7 +486,7 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t * } offset = 0; } else { - p = (void *)&in[offset - 1]; + p = &in[offset - 1]; /* character reference */ ++offset; if (isdigit(in[offset])) { @@ -486,7 +505,7 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t * n = (LY_BASE_HEX * n) + u; } } else { - LOGVAL(ctx, LYVE_SYNTAX, "Invalid character reference \"%.*s\".", 12, p); + LOGVAL(ctx, LYVE_SYNTAX, "Invalid character reference \"%.12s\".", p); goto error; } @@ -497,7 +516,7 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t * } ++offset; if (ly_pututf8(&buf[len], n, &u)) { - LOGVAL(ctx, LYVE_SYNTAX, "Invalid character reference \"%.*s\" (0x%08x).", 12, p, n); + LOGVAL(ctx, LYVE_SYNTAX, "Invalid character reference \"%.12s\" (0x%08x).", p, n); goto error; } len += u; |