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.
This commit is contained in:
Campbell Barton
2023-05-03 10:23:00 +10:00
parent 4115fcbc38
commit f30434ac99
6 changed files with 11 additions and 6 deletions

View File

@@ -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.
*/

View File

@@ -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

View File

@@ -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,

View File

@@ -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,

View File

@@ -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. */

View File

@@ -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;
}