summaryrefslogtreecommitdiff
path: root/src/rexmpp_xml_parser.c
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2023-09-29 20:24:16 +0300
committerdefanor <defanor@uberspace.net>2023-09-29 20:24:16 +0300
commitccdb748c81abc9bb30b8989e27d22bbbb219f9a0 (patch)
tree295be2ea605c8acbe56116ea3ce119b99e3e0440 /src/rexmpp_xml_parser.c
parent04e6fd5194481798bc30abc7a690664d5af36aeb (diff)
Add more checks, tests, and documentation
Diffstat (limited to 'src/rexmpp_xml_parser.c')
-rw-r--r--src/rexmpp_xml_parser.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/rexmpp_xml_parser.c b/src/rexmpp_xml_parser.c
index e00c70c..3f485d7 100644
--- a/src/rexmpp_xml_parser.c
+++ b/src/rexmpp_xml_parser.c
@@ -41,13 +41,15 @@ void rexmpp_xml_sax_elem_start (rexmpp_xml_parser_ctx_t ctx,
for (i = nb_attributes - 1; i >= 0; i--) {
size_t attr_len = attributes[i * 5 + 4] - attributes[i * 5 + 3];
char *attr_val = malloc(attr_len + 1);
- attr_val[attr_len] = '\0';
- strncpy(attr_val, attributes[i * 5 + 3], attr_len);
- rexmpp_xml_attr_t *attr =
- rexmpp_xml_attr_new(attributes[i * 5], NULL, attr_val);
- free(attr_val);
- attr->next = attrs;
- attrs = attr;
+ if (attr_val != NULL) {
+ attr_val[attr_len] = '\0';
+ strncpy(attr_val, attributes[i * 5 + 3], attr_len);
+ rexmpp_xml_attr_t *attr =
+ rexmpp_xml_attr_new(attributes[i * 5], NULL, attr_val);
+ free(attr_val);
+ attr->next = attrs;
+ attrs = attr;
+ }
}
ctx->handlers->elem_start(ctx->user_data, localname, URI, attrs);