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:
authorSybren A. Stüvel <sybren@stuvel.eu>2018-06-26 18:35:04 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2018-06-26 18:35:21 +0300
commit599e979d90327c1e10031f992cb2be2cda414825 (patch)
treef645195421bc559cb23a36433c4d2bae4f835a60
parent73eb1bfd55d51f1dfeb6c49560e0096c9214a105 (diff)
Fix bug in DNA_struct_elem_find when checking the first field
find_elem(olddata=NULL) doesn't work reliably for existence checks; it will return NULL both when the field is found at offset 0 and when it is not found at all.
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index 32e41863ad1..d8d29c9c812 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -894,10 +894,47 @@ static int elem_strcmp(const char *name, const char *oname)
}
/**
+ * Returns whether the specified field exists according to the struct format
+ * pointed to by old.
+ *
+ * \param sdna Old SDNA
+ * \param type Current field type name
+ * \param name Current field name
+ * \param old Pointer to struct information in sdna
+ * \return true when existsing, false otherwise.
+ */
+static bool elem_exists(
+ const SDNA *sdna,
+ const char *type,
+ const char *name,
+ const short *old)
+{
+ int a, elemcount;
+ const char *otype, *oname;
+
+ /* in old is the old struct */
+ elemcount = old[1];
+ old += 2;
+ for (a = 0; a < elemcount; a++, old += 2) {
+ otype = sdna->types[old[0]];
+ oname = sdna->names[old[1]];
+
+ if (elem_strcmp(name, oname) == 0) { /* name equal */
+ return strcmp(type, otype) == 0; /* type equal */
+ }
+ }
+ return false;
+}
+
+/**
* Returns the address of the data for the specified field within olddata
* according to the struct format pointed to by old, or NULL if no such
* field can be found.
*
+ * Passing olddata=NULL doesn't work reliably for existence checks; it will
+ * return NULL both when the field is found at offset 0 and when it is not
+ * found at all. For field existence checks, use elem_exists() instead.
+ *
* \param sdna Old SDNA
* \param type Current field type name
* \param name Current field name
@@ -1307,9 +1344,9 @@ bool DNA_struct_elem_find(const SDNA *sdna, const char *stype, const char *varty
if (SDNAnr != -1) {
const short * const spo = sdna->structs[SDNAnr];
- const char * const cp = find_elem(sdna, vartype, name, spo, NULL, NULL);
+ const bool found = elem_exists(sdna, vartype, name, spo);
- if (cp) {
+ if (found) {
return true;
}
}