diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-02 18:20:00 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-02 18:21:31 +0300 |
commit | 7f3649874070de38131263317d02906d50279f93 (patch) | |
tree | 9d1a27e88a29ec84519d2b785554f00c22cf273e /source/blender/blenkernel/intern/cryptomatte.cc | |
parent | b3886c1f2adfb2d63b471d137bd7b42b68fbfb1d (diff) |
Fix T86026: Crash Opening Cryptomatte File.
Not sure this fixes the root cause. It seems that memory corruption
happens in dynstr. This patch replaces dynstr with a streamstring.
Diffstat (limited to 'source/blender/blenkernel/intern/cryptomatte.cc')
-rw-r--r-- | source/blender/blenkernel/intern/cryptomatte.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc index a20c53ed270..8a6b89ce19e 100644 --- a/source/blender/blenkernel/intern/cryptomatte.cc +++ b/source/blender/blenkernel/intern/cryptomatte.cc @@ -184,22 +184,30 @@ float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash) char *BKE_cryptomatte_entries_to_matte_id(NodeCryptomatte *node_storage) { - DynStr *matte_id = BLI_dynstr_new(); + std::stringstream ss; + ss.precision(9); + bool first = true; LISTBASE_FOREACH (CryptomatteEntry *, entry, &node_storage->entries) { if (!first) { - BLI_dynstr_append(matte_id, ","); + ss << ','; } - if (BLI_strnlen(entry->name, sizeof(entry->name)) != 0) { - BLI_dynstr_nappend(matte_id, entry->name, sizeof(entry->name)); + blender::StringRef entry_name(entry->name, BLI_strnlen(entry->name, sizeof(entry->name))); + if (!entry_name.is_empty()) { + ss << entry_name; } else { - BLI_dynstr_appendf(matte_id, "<%.9g>", entry->encoded_hash); + ss << '<' << std::scientific << entry->encoded_hash << '>'; } first = false; } - char *result = BLI_dynstr_get_cstring(matte_id); - BLI_dynstr_free(matte_id); + + /* Convert result to C string. */ + const std::string result_string = ss.str(); + const char *c_str = result_string.c_str(); + size_t result_len = result_string.size() + 1; + char *result = static_cast<char *>(MEM_mallocN(sizeof(char) * result_len, __func__)); + memcpy(result, c_str, result_len); return result; } |