diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 1 |
4 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 400944d60d4..b5354514205 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -3030,7 +3030,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA } if (dparm->next) { - fprintf(f, "\t_data += %d;\n", rna_parameter_size(dparm->prop)); + fprintf(f, "\t_data += %d;\n", rna_parameter_size_pad(rna_parameter_size(dparm->prop))); } } diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 0bc35d86490..a0b25cf60b2 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -7130,7 +7130,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, /* allocate data */ for (parm = func->cont.properties.first; parm; parm = parm->next) { - alloc_size += rna_parameter_size(parm); + alloc_size += rna_parameter_size_pad(rna_parameter_size(parm)); if (parm->flag_parameter & PARM_OUTPUT) { parms->ret_count++; @@ -7206,7 +7206,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, } } - data = ((char *)data) + rna_parameter_size(parm); + data = ((char *)data) + rna_parameter_size_pad(size); } return parms; @@ -7230,7 +7230,7 @@ void RNA_parameter_list_free(ParameterList *parms) } } - tot += rna_parameter_size(parm); + tot += rna_parameter_size_pad(rna_parameter_size(parm)); } MEM_freeN(parms->data); @@ -7272,7 +7272,7 @@ void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter) void RNA_parameter_list_next(ParameterIterator *iter) { - iter->offset += iter->size; + iter->offset += rna_parameter_size_pad(iter->size); iter->parm = iter->parm->next; iter->valid = iter->parm != NULL; diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 9d26797aa88..a747a5d11d8 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -4421,6 +4421,16 @@ int rna_parameter_size(PropertyRNA *parm) return sizeof(void *); } +int rna_parameter_size_pad(const int size) +{ + /* Pad parameters in memory so the next parameter is properly aligned. + * This silences warnings in ubsan. More complicated logic to pack parameters + * more tightly in memory is unlikely to improve performance, and aligning + * to the requirements for pointers is enough for all data types we use. */ + const int alignment = sizeof(void *); + return (size + alignment - 1) & ~(alignment - 1); +} + /* Dynamic Enums */ void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item) diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 9e743a4f205..6ca8e668fa0 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -635,6 +635,7 @@ PointerRNA rna_pointer_inherit_refine(struct PointerRNA *ptr, struct StructRNA * /* Functions */ int rna_parameter_size(struct PropertyRNA *parm); +int rna_parameter_size_pad(const int size); /* XXX, these should not need to be defined here~! */ struct MTex *rna_mtex_texture_slots_add(struct ID *self, |