Fix: Escape property name when keying #119922

Merged
Christoph Lendenfeld merged 3 commits from ChrisLend/blender:fix_escape_property_name into main 2024-04-02 16:25:11 +02:00
2 changed files with 6 additions and 3 deletions

View File

@ -10,6 +10,7 @@ set(INC
../../makesrna
../../sequencer
../../windowmanager
../../../../extern/fmtlib/include
# RNA_prototypes.h
${CMAKE_BINARY_DIR}/source/blender/makesrna
)

View File

@ -9,6 +9,8 @@
#include <cstddef>
#include <cstdio>
#include <fmt/format.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
@ -298,9 +300,9 @@ static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr)
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_CUSTOM_PROPERTIES) {
if (properties) {
LISTBASE_FOREACH (IDProperty *, prop, &properties->data.group) {
std::string name = prop->name;
std::string rna_path = "[\"" + name + "\"]";
paths.append(rna_path);
char name_escaped[MAX_IDPROP_NAME * 2];
Review

This will leak the result of BLI_sprintfN which allocates a char *. It should be replaced by fmt::format

This will leak the result of `BLI_sprintfN` which allocates a `char *`. It should be replaced by `fmt::format`

thanks, changed :)

thanks, changed :)
BLI_str_escape(name_escaped, prop->name, sizeof(name_escaped));
paths.append(fmt::format("[\"{}\"]", name_escaped));
}
Review

To avoid copying the string, use std::move or put the fmt::format call directly inside append(..)

To avoid copying the string, use `std::move` or put the `fmt::format` call directly inside `append(..)`
}
}