From 83d487aa626b001c8d3fe2b3d1b2eac773653065 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 1 Oct 2021 08:45:25 +0800 Subject: [PATCH] Mark shallow copy as page shared to avoid reuse --- src/pugixml.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 950d3ab..ca10ba9 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2345,7 +2345,8 @@ PUGI__NS_BEGIN size_t target_length = strlength(target); // always reuse document buffer memory if possible - if ((header & header_mask) == 0) return target_length >= length; + if ((header & header_mask) == 0) + return target_length >= length; // reuse heap memory if waste is not too great const size_t reuse_threshold = 32; @@ -2367,6 +2368,9 @@ PUGI__NS_BEGIN dest = source_length == 0 ? 0 : const_cast(source); header &= ~header_mask; + // since strcpy_insitu can reuse document buffer memory we need to mark both dest as shared + header |= xml_memory_page_contents_shared_mask; + return true; } else if (dest && strcpy_insitu_allow(source_length, header, header_mask, dest))