From a469fa2cfc9f0202fa7631a80f67bffbda01fa2e Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 19 Mar 2023 14:57:10 -0700 Subject: [PATCH] Add assertion about header-dest relation to strcpy_insitu May improve static analysis behavior for #555. --- src/pugixml.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index beec50c..2f15073 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2374,6 +2374,8 @@ PUGI_IMPL_NS_BEGIN template PUGI_IMPL_FN bool strcpy_insitu(String& dest, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length) { + assert((header & header_mask) == 0 || dest); // header bit indicates whether dest was previously allocated + if (source_length == 0) { // empty string and null pointer are equivalent, so just deallocate old memory @@ -4408,7 +4410,7 @@ PUGI_IMPL_NS_BEGIN template PUGI_IMPL_FN void node_copy_string(String& dest, Header& header, uintptr_t header_mask, char_t* source, Header& source_header, xml_allocator* alloc) { - assert(!dest && (header & header_mask) == 0); + assert(!dest && (header & header_mask) == 0); // copies are performed into fresh nodes if (source) {