Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-09-04 07:22:44 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-04 09:59:54 +0300
commite6194e735791b42feb51e810a4910a41d999d3bf (patch)
tree95889982ba8c6bc88f5bdfb2eded77159d81ca89 /source/blender/blenkernel/intern
parent716682365c6bcc1b5f757232ce1d2499b0d062a9 (diff)
RNA: support extracting names from paths without allocating memory
Support extracting identifiers RNA paths into fixed size buffer since the maximum size of the identifier is known all cases. - Add BLI_str_unescape_ex to support limiting the destination buffer. - Add BLI_str_quoted_substr to copy values into a fixed size buffer.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/action_bones.cc6
-rw-r--r--source/blender/blenkernel/intern/fcurve.c24
2 files changed, 15 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/action_bones.cc b/source/blender/blenkernel/intern/action_bones.cc
index b8d185e6a81..1f2b7360b70 100644
--- a/source/blender/blenkernel/intern/action_bones.cc
+++ b/source/blender/blenkernel/intern/action_bones.cc
@@ -28,6 +28,7 @@
#include "DNA_action_types.h"
#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
#include "MEM_guardedalloc.h"
@@ -36,12 +37,11 @@ namespace blender::bke {
void BKE_action_find_fcurves_with_bones(const bAction *action, FoundFCurveCallback callback)
{
LISTBASE_FOREACH (FCurve *, fcu, &action->curves) {
- char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
- if (!bone_name) {
+ char bone_name[MAXBONENAME];
+ if (!BLI_str_quoted_substr(fcu->rna_path, "pose.bones[", bone_name, sizeof(bone_name))) {
continue;
}
callback(fcu, bone_name);
- MEM_freeN(bone_name);
}
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index fb6cd5871f4..8e9c504dcbf 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -346,30 +346,30 @@ int BKE_fcurves_filter(ListBase *dst, ListBase *src, const char *dataPrefix, con
return 0;
}
+ const size_t quotedName_size = strlen(dataName) + 1;
+ char *quotedName = alloca(quotedName_size);
+
/* Search each F-Curve one by one. */
for (fcu = src->first; fcu; fcu = fcu->next) {
/* Check if quoted string matches the path. */
if (fcu->rna_path == NULL) {
continue;
}
-
- char *quotedName = BLI_str_quoted_substrN(fcu->rna_path, dataPrefix);
- if (quotedName == NULL) {
+ /* Skipping names longer than `quotedName_size` is OK since we're after an exact match. */
+ if (!BLI_str_quoted_substr(fcu->rna_path, dataPrefix, quotedName, quotedName_size)) {
+ continue;
+ }
+ if (!STREQ(quotedName, dataName)) {
continue;
}
/* Check if the quoted name matches the required name. */
- if (STREQ(quotedName, dataName)) {
- LinkData *ld = MEM_callocN(sizeof(LinkData), __func__);
-
- ld->data = fcu;
- BLI_addtail(dst, ld);
+ LinkData *ld = MEM_callocN(sizeof(LinkData), __func__);
- matches++;
- }
+ ld->data = fcu;
+ BLI_addtail(dst, ld);
- /* Always free the quoted string, since it needs freeing. */
- MEM_freeN(quotedName);
+ matches++;
}
/* Return the number of matches. */
return matches;