From: Fletcher T. Penney Date: Thu, 16 Mar 2017 01:06:01 +0000 (-0400) Subject: FIXED: Fix bug in transclusion code X-Git-Tag: 6.0.0-rc2^2~22^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75847fc519c2795887ee8b206fcedf04b9c972b6;p=multimarkdown FIXED: Fix bug in transclusion code --- diff --git a/Sources/libMultiMarkdown/transclude.c b/Sources/libMultiMarkdown/transclude.c index c744033..ea28f9b 100644 --- a/Sources/libMultiMarkdown/transclude.c +++ b/Sources/libMultiMarkdown/transclude.c @@ -326,8 +326,8 @@ void transclude_source(DString * source, const char * dir, short format, stack * if (stop == NULL) break; - // Where will we start next search? - offset = stop + 2 - source->str; + // Remember insertion point + offset = start + 2 - source->str; // Ensure we have a reasonable match -- cap at 1000 characters if (stop - start < 1000) { @@ -432,11 +432,12 @@ void transclude_source(DString * source, const char * dir, short format, stack * mmd_engine_free(e, false); - // Insert file text + // Insert file text -- this may cause d_string to reallocate the + // character buffer, meaning start/stop are no longer valid d_string_insert(source, start - source->str, buffer->str); // Shift search point - offset = start - source->str + buffer->currentStringLength; + offset += buffer->currentStringLength; d_string_free(buffer, true); }