From f30434ac99c412ea20de62bf524fc31fba8425e1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 May 2023 10:23:00 +1000 Subject: [PATCH] BLI_string_utils: BLI_uniquename no longer accepts NULL defname A NULL defname would early exit (doing nothing) this isn't good behavior as this function should always make the name unique and a NULL defname is likely an error in the code which would allow duplicate names. This is also inconsistent with BLI_uniquename_cb which always wrote the defname into the name if it was empty. Mark this argument as never-NULL. --- source/blender/blenkernel/BKE_asset.h | 3 ++- source/blender/blenkernel/BKE_particle.h | 4 +++- source/blender/blenkernel/intern/attribute.cc | 3 ++- source/blender/blenkernel/intern/customdata.cc | 3 ++- source/blender/blenlib/BLI_string_utils.h | 2 +- source/blender/blenlib/intern/string_utils.c | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h index 9d30edd2b99..d162a5883b5 100644 --- a/source/blender/blenkernel/BKE_asset.h +++ b/source/blender/blenkernel/BKE_asset.h @@ -42,7 +42,8 @@ struct AssetTagEnsureResult { bool is_new; }; -struct AssetTag *BKE_asset_metadata_tag_add(struct AssetMetaData *asset_data, const char *name); +struct AssetTag *BKE_asset_metadata_tag_add(struct AssetMetaData *asset_data, const char *name) + ATTR_NONNULL(1, 2); /** * Make sure there is a tag with name \a name, create one if needed. */ diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 8dc14d5c370..c34f118e3b6 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -9,6 +9,7 @@ */ #include "BLI_buffer.h" +#include "BLI_compiler_attrs.h" #include "BLI_utildefines.h" #include "DNA_particle_types.h" @@ -376,7 +377,8 @@ void psys_reset(struct ParticleSystem *psys, int mode); void psys_find_parents(struct ParticleSimulationData *sim, bool use_render_params); -void psys_unique_name(struct Object *object, struct ParticleSystem *psys, const char *defname); +void psys_unique_name(struct Object *object, struct ParticleSystem *psys, const char *defname) + ATTR_NONNULL(1, 2, 3); /** * Calculates paths ready for drawing/rendering diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 82ea3b1cf6c..97fcff343da 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -265,7 +265,8 @@ bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname) BLI_strncpy_utf8(outname, name, maxlength); } - return BLI_uniquename_cb(unique_name_cb, &data, nullptr, '.', outname, maxlength); + const char *defname = ""; /* Dummy argument, never used as `name` is never zero length. */ + return BLI_uniquename_cb(unique_name_cb, &data, defname, '.', outname, maxlength); } CustomDataLayer *BKE_id_attribute_new(ID *id, diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index f71f0a51c96..3d1919c57db 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -4416,7 +4416,8 @@ void CustomData_set_layer_unique_name(CustomData *data, const int index) STRNCPY(nlayer->name, DATA_(typeInfo->defaultname)); } - BLI_uniquename_cb(customdata_unique_check, &data_arg, nullptr, '.', nlayer->name, max_length); + const char *defname = ""; /* Dummy argument, never used as `name` is never zero length. */ + BLI_uniquename_cb(customdata_unique_check, &data_arg, defname, '.', nlayer->name, max_length); } void CustomData_validate_layer_name(const CustomData *data, diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 8917f280228..91c3c9ea190 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -112,7 +112,7 @@ bool BLI_uniquename(struct ListBase *list, const char *defname, char delim, int name_offset, - size_t name_len) ATTR_NONNULL(1); + size_t name_len) ATTR_NONNULL(1, 3); /* Expand array functions. */ diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index bbcc7fb1bf8..0c3bb5bfc09 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -321,7 +321,7 @@ bool BLI_uniquename( BLI_assert(name_len > 1); /* See if we are given an empty string */ - if (ELEM(NULL, vlink, defname)) { + if (ELEM(NULL, vlink)) { return false; }