@@ -385,22 +385,22 @@ void static inline parse_tag(document* d)
385385{
386386 node_alloc(&d->nodes, 1);
387387 d->nodes.used_back++;
388− int me = d->nodes.size - d->nodes.used_back;
388+ node* me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back];
389389
390− d->nodes.nodes[me].outer.start = doc_position(d);
390+ me->outer.start = doc_position(d);
391391 char c = get(d);
392392 assert(c == '<');
393393 if (peek(d) == '?') skip(d, 1);
394− d->nodes.nodes[me].name = parse_name(d);
395− d->nodes.nodes[me].attrs = parse_attributes(d);
394+ me->name = parse_name(d);
395+ me->attrs = parse_attributes(d);
396396
397397 c = get(d);
398398 if ((c == '/' || c == '?') && peek(d) == '>')
399399 {
400400 skip(d, 1);
401− d->nodes.nodes[me].nodes = start_length(0, 0);
402− d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, doc_position(d)).length;
403− d->nodes.nodes[me].inner = start_length(doc_position(d), 0);
401+ me->nodes = start_length(0, 0);
402+ me->outer.length = start_end(me->outer.start, doc_position(d)).length;
403+ me->inner = start_length(doc_position(d), 0);
404404 return;
405405 }
406406 else if (c != '>')
@@ -408,22 +408,26 @@ void static inline parse_tag(document* d)
408408 set_error(d, "Gunk at the end of the tag");
409409 return;
410410 }
411− d->nodes.nodes[me].inner.start = doc_position(d);
412− d->nodes.nodes[me].nodes = parse_content(d);
413− d->nodes.nodes[me].inner.length = start_end(d->nodes.nodes[me].inner.start, doc_position(d)).length;
411+ me->inner.start = doc_position(d);
412+ str content = parse_content(d);
413+
414+ // parse_content may have allocated more nodes, so recompute me
415+ me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back];
416+ me->nodes = content;
417+ me->inner.length = start_end(me->inner.start, doc_position(d)).length;
414418
415419 if (d->error_message != NULL) return;
416420 if (peek(d) == '<' && peekAt(d, 1) == '/')
417421 {
418422 skip(d, 2);
419− if (d->end - d->cursor >= d->nodes.nodes[me].name.length &&
420− memcmp(d->cursor, &d->body[d->nodes.nodes[me].name.start], d->nodes.nodes[me].name.length) == 0)
423+ if (d->end - d->cursor >= me->name.length &&
424+ memcmp(d->cursor, &d->body[me->name.start], me->name.length) == 0)
421425 {
422− skip(d, d->nodes.nodes[me].name.length);
426+ skip(d, me->name.length);
423427 trim(d);
424428 if (get(d) == '>')
425429 {
426− d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, doc_position(d)).length;
430+ me->outer.length = start_end(me->outer.start, doc_position(d)).length;
427431 return;
428432 }
429433 }