Cleanup: reserve the term 'len' for string length
This commit is contained in:
@@ -47,7 +47,7 @@ float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash);
|
||||
bool BKE_cryptomatte_find_name(const struct CryptomatteSession *session,
|
||||
float encoded_hash,
|
||||
char *r_name,
|
||||
int name_len);
|
||||
int name_maxncpy);
|
||||
|
||||
char *BKE_cryptomatte_entries_to_matte_id(struct NodeCryptomatte *node_storage);
|
||||
void BKE_cryptomatte_matte_id_to_entries(struct NodeCryptomatte *node_storage,
|
||||
|
||||
@@ -118,9 +118,15 @@ struct CryptomatteStampDataCallbackData {
|
||||
static blender::StringRef extract_layer_hash(blender::StringRefNull key);
|
||||
|
||||
/* C type callback function (StampCallback). */
|
||||
static void extract_layer_names(void *_data, const char *propname, char *propvalue, int len);
|
||||
static void extract_layer_names(void *_data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int propvalue_maxncpy);
|
||||
/* C type callback function (StampCallback). */
|
||||
static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int len);
|
||||
static void extract_layer_manifest(void *_data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int propvalue_maxncpy);
|
||||
};
|
||||
|
||||
const blender::Vector<std::string> &BKE_cryptomatte_layer_names_get(
|
||||
|
||||
@@ -50,7 +50,10 @@ void BKE_image_free_gputextures(struct Image *ima);
|
||||
*/
|
||||
void BKE_image_free_data(struct Image *image);
|
||||
|
||||
typedef void(StampCallback)(void *data, const char *propname, char *propvalue, int len);
|
||||
typedef void(StampCallback)(void *data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int propvalue_maxncpy);
|
||||
|
||||
void BKE_render_result_stamp_info(struct Scene *scene,
|
||||
struct Object *camera,
|
||||
|
||||
@@ -169,7 +169,7 @@ static void action_flip_pchan(Object *ob_arm,
|
||||
BLI_str_escape(pchan_name_esc, pchan->name, sizeof(pchan_name_esc));
|
||||
const int path_xform_prefix_len = SNPRINTF(path_xform, "pose.bones[\"%s\"]", pchan_name_esc);
|
||||
char *path_xform_suffix = path_xform + path_xform_prefix_len;
|
||||
const int path_xform_suffix_len = sizeof(path_xform) - path_xform_prefix_len;
|
||||
const int path_xform_suffix_maxncpy = sizeof(path_xform) - path_xform_prefix_len;
|
||||
|
||||
/* Lookup and assign all available #FCurve channels,
|
||||
* unavailable channels are left NULL. */
|
||||
@@ -191,11 +191,11 @@ static void action_flip_pchan(Object *ob_arm,
|
||||
} fkc_pchan = {{{NULL}}};
|
||||
|
||||
#define FCURVE_ASSIGN_VALUE(id, path_test_suffix, index) \
|
||||
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_len); \
|
||||
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_maxncpy); \
|
||||
action_flip_pchan_cache_fcurve_assign_value(&fkc_pchan.id, index, path_xform, fcache)
|
||||
|
||||
#define FCURVE_ASSIGN_ARRAY(id, path_test_suffix) \
|
||||
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_len); \
|
||||
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_maxncpy); \
|
||||
action_flip_pchan_cache_fcurve_assign_array( \
|
||||
fkc_pchan.id, ARRAY_SIZE(fkc_pchan.id), path_xform, fcache)
|
||||
|
||||
|
||||
@@ -173,10 +173,10 @@ bool BKE_id_attribute_rename(ID *id,
|
||||
* is clamped to it's maximum length, otherwise assigning an over-long name multiple times
|
||||
* will add `.001` suffix unnecessarily. */
|
||||
{
|
||||
const int maxlength = CustomData_name_max_length_calc(new_name);
|
||||
const int new_name_maxncpy = CustomData_name_max_length_calc(new_name);
|
||||
/* NOTE: A function that performs a clamped comparison without copying would be handy here. */
|
||||
char new_name_clamped[MAX_CUSTOMDATA_LAYER_NAME];
|
||||
BLI_strncpy_utf8(new_name_clamped, new_name, maxlength);
|
||||
BLI_strncpy_utf8(new_name_clamped, new_name, new_name_maxncpy);
|
||||
if (STREQ(old_name, new_name_clamped)) {
|
||||
return false;
|
||||
}
|
||||
@@ -254,19 +254,19 @@ static bool unique_name_cb(void *arg, const char *name)
|
||||
bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
|
||||
{
|
||||
AttrUniqueData data{id};
|
||||
const int maxlength = CustomData_name_max_length_calc(name);
|
||||
const int name_maxncpy = CustomData_name_max_length_calc(name);
|
||||
|
||||
/* Set default name if none specified.
|
||||
* NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */
|
||||
if (!name || name[0] == '\0') {
|
||||
BLI_strncpy(outname, IFACE_("Attribute"), maxlength);
|
||||
BLI_strncpy(outname, IFACE_("Attribute"), name_maxncpy);
|
||||
}
|
||||
else {
|
||||
BLI_strncpy_utf8(outname, name, maxlength);
|
||||
BLI_strncpy_utf8(outname, name, name_maxncpy);
|
||||
}
|
||||
|
||||
const char *defname = ""; /* Dummy argument, never used as `name` is never zero length. */
|
||||
return BLI_uniquename_cb(unique_name_cb, &data, defname, '.', outname, maxlength);
|
||||
return BLI_uniquename_cb(unique_name_cb, &data, defname, '.', outname, name_maxncpy);
|
||||
}
|
||||
|
||||
CustomDataLayer *BKE_id_attribute_new(ID *id,
|
||||
|
||||
@@ -219,14 +219,14 @@ float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash)
|
||||
bool BKE_cryptomatte_find_name(const CryptomatteSession *session,
|
||||
const float encoded_hash,
|
||||
char *r_name,
|
||||
int name_len)
|
||||
int name_maxncpy)
|
||||
{
|
||||
std::optional<std::string> name = (*session)[encoded_hash];
|
||||
if (!name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BLI_strncpy(r_name, name->c_str(), name_len);
|
||||
BLI_strncpy(r_name, name->c_str(), name_maxncpy);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ blender::StringRef CryptomatteStampDataCallbackData::extract_layer_hash(blender:
|
||||
void CryptomatteStampDataCallbackData::extract_layer_names(void *_data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int /*len*/)
|
||||
int /*propvalue_maxncpy*/)
|
||||
{
|
||||
CryptomatteStampDataCallbackData *data = static_cast<CryptomatteStampDataCallbackData *>(_data);
|
||||
|
||||
@@ -598,7 +598,7 @@ void CryptomatteStampDataCallbackData::extract_layer_names(void *_data,
|
||||
void CryptomatteStampDataCallbackData::extract_layer_manifest(void *_data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int /*len*/)
|
||||
int /*propvalue_maxncpy*/)
|
||||
{
|
||||
CryptomatteStampDataCallbackData *data = static_cast<CryptomatteStampDataCallbackData *>(_data);
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ TEST(cryptomatte, extract_layer_hash_from_metadata_key)
|
||||
static void validate_cryptomatte_session_from_stamp_data(void * /*data*/,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int /*len*/)
|
||||
int /*propvalue_maxncpy*/)
|
||||
{
|
||||
blender::StringRefNull prop_name(propname);
|
||||
if (!prop_name.startswith("cryptomatte/")) {
|
||||
|
||||
@@ -2486,18 +2486,24 @@ void BKE_stamp_data_free(StampData *stamp_data)
|
||||
}
|
||||
|
||||
/* wrap for callback only */
|
||||
static void metadata_set_field(void *data, const char *propname, char *propvalue, int /*len*/)
|
||||
static void metadata_set_field(void *data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int /*propvalue_maxncpy*/)
|
||||
{
|
||||
/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
|
||||
ImBuf *imbuf = static_cast<ImBuf *>(data);
|
||||
IMB_metadata_set_field(imbuf->metadata, propname, propvalue);
|
||||
}
|
||||
|
||||
static void metadata_get_field(void *data, const char *propname, char *propvalue, int len)
|
||||
static void metadata_get_field(void *data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int propvalue_maxncpy)
|
||||
{
|
||||
/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
|
||||
ImBuf *imbuf = static_cast<ImBuf *>(data);
|
||||
IMB_metadata_get_field(imbuf->metadata, propname, propvalue, len);
|
||||
IMB_metadata_get_field(imbuf->metadata, propname, propvalue, propvalue_maxncpy);
|
||||
}
|
||||
|
||||
void BKE_imbuf_stamp_info(const RenderResult *rr, ImBuf *ibuf)
|
||||
|
||||
@@ -481,9 +481,9 @@ char *BKE_packedfile_unpack_to_file(ReportList *reports,
|
||||
static void unpack_generate_paths(const char *filepath,
|
||||
ID *id,
|
||||
char *r_abspath,
|
||||
size_t abspath_maxncpy,
|
||||
char *r_relpath,
|
||||
size_t abspathlen,
|
||||
size_t relpathlen)
|
||||
size_t relpath_maxncpy)
|
||||
{
|
||||
const short id_type = GS(id->name);
|
||||
char temp_filename[FILE_MAX];
|
||||
@@ -545,13 +545,13 @@ static void unpack_generate_paths(const char *filepath,
|
||||
break;
|
||||
}
|
||||
if (dir_name) {
|
||||
BLI_path_join(r_relpath, relpathlen, "//", dir_name, temp_filename);
|
||||
BLI_path_join(r_relpath, relpath_maxncpy, "//", dir_name, temp_filename);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
size_t len = BLI_strncpy_rlen(r_abspath, temp_dirname, abspathlen);
|
||||
BLI_strncpy(r_abspath + len, temp_filename, abspathlen - len);
|
||||
size_t len = BLI_strncpy_rlen(r_abspath, temp_dirname, abspath_maxncpy);
|
||||
BLI_strncpy(r_abspath + len, temp_filename, abspath_maxncpy - len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ char *BKE_packedfile_unpack(Main *bmain,
|
||||
|
||||
if (id != NULL) {
|
||||
unpack_generate_paths(
|
||||
orig_file_path, id, absname, localname, sizeof(absname), sizeof(localname));
|
||||
orig_file_path, id, absname, sizeof(absname), localname, sizeof(localname));
|
||||
new_name = BKE_packedfile_unpack_to_file(
|
||||
reports, BKE_main_blendfile_path(bmain), absname, localname, pf, how);
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value)
|
||||
static void ffmpeg_add_metadata_callback(void *data,
|
||||
const char *propname,
|
||||
char *propvalue,
|
||||
int UNUSED(len))
|
||||
int UNUSED(propvalue_maxncpy))
|
||||
{
|
||||
AVDictionary **metadata = (AVDictionary **)data;
|
||||
av_dict_set(metadata, propname, propvalue, 0);
|
||||
|
||||
@@ -38,11 +38,14 @@ void IMB_metadata_free(struct IDProperty *metadata);
|
||||
* \param metadata: the #IDProperty that contains the metadata
|
||||
* \param key: the key of the field
|
||||
* \param value: the data in the field, first one found with key is returned,
|
||||
* memory has to be allocated by user.
|
||||
* memory has to be allocated by user.
|
||||
* \param len: length of value buffer allocated by user.
|
||||
* \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise.
|
||||
*/
|
||||
bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len);
|
||||
bool IMB_metadata_get_field(struct IDProperty *metadata,
|
||||
const char *key,
|
||||
char *value,
|
||||
size_t value_maxncpy);
|
||||
|
||||
/**
|
||||
* Set user data in the metadata.
|
||||
|
||||
@@ -378,16 +378,16 @@ int IMB_timecode_to_array_index(IMB_Timecode_Type tc)
|
||||
* - rebuild helper functions
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
static void get_index_dir(struct anim *anim, char *index_dir, size_t index_dir_len)
|
||||
static void get_index_dir(struct anim *anim, char *index_dir, size_t index_dir_maxncpy)
|
||||
{
|
||||
if (!anim->index_dir[0]) {
|
||||
char filename[FILE_MAXFILE];
|
||||
char dirname[FILE_MAXDIR];
|
||||
BLI_path_split_dir_file(anim->filepath, dirname, sizeof(dirname), filename, sizeof(filename));
|
||||
BLI_path_join(index_dir, index_dir_len, dirname, "BL_proxy", filename);
|
||||
BLI_path_join(index_dir, index_dir_maxncpy, dirname, "BL_proxy", filename);
|
||||
}
|
||||
else {
|
||||
BLI_strncpy(index_dir, anim->index_dir, index_dir_len);
|
||||
BLI_strncpy(index_dir, anim->index_dir, index_dir_maxncpy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ void IMB_metadata_free(struct IDProperty *metadata)
|
||||
|
||||
bool IMB_metadata_get_field(struct IDProperty *metadata,
|
||||
const char *key,
|
||||
char *field,
|
||||
const size_t len)
|
||||
char *value,
|
||||
const size_t value_maxncpy)
|
||||
{
|
||||
IDProperty *prop;
|
||||
|
||||
@@ -56,7 +56,7 @@ bool IMB_metadata_get_field(struct IDProperty *metadata,
|
||||
prop = IDP_GetPropertyFromGroup(metadata, key);
|
||||
|
||||
if (prop && prop->type == IDP_STRING) {
|
||||
BLI_strncpy(field, IDP_String(prop), len);
|
||||
BLI_strncpy(value, IDP_String(prop), value_maxncpy);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1010,11 +1010,11 @@ void ArmatureImporter::set_tags_map(TagsMap &tags_map)
|
||||
|
||||
void ArmatureImporter::get_rna_path_for_joint(COLLADAFW::Node *node,
|
||||
char *joint_path,
|
||||
size_t count)
|
||||
size_t joint_path_maxncpy)
|
||||
{
|
||||
char bone_name_esc[sizeof(Bone::name) * 2];
|
||||
BLI_str_escape(bone_name_esc, bc_get_joint_name(node), sizeof(bone_name_esc));
|
||||
BLI_snprintf(joint_path, count, "pose.bones[\"%s\"]", bone_name_esc);
|
||||
BLI_snprintf(joint_path, joint_path_maxncpy, "pose.bones[\"%s\"]", bone_name_esc);
|
||||
}
|
||||
|
||||
bool ArmatureImporter::get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint)
|
||||
|
||||
@@ -171,7 +171,7 @@ class ArmatureImporter : private TransformReader {
|
||||
|
||||
Object *get_armature_for_joint(COLLADAFW::Node *node);
|
||||
|
||||
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count);
|
||||
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t joint_path_maxncpy);
|
||||
|
||||
/** Gives a world-space mat. */
|
||||
bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint);
|
||||
|
||||
@@ -380,7 +380,7 @@ void RNA_property_string_search(const struct bContext *C,
|
||||
* \return the length without `\0` terminator.
|
||||
*/
|
||||
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop);
|
||||
void RNA_property_string_get_default(PropertyRNA *prop, char *value, int max_len);
|
||||
void RNA_property_string_get_default(PropertyRNA *prop, char *value, int value_maxncpy);
|
||||
char *RNA_property_string_get_default_alloc(
|
||||
PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len);
|
||||
/**
|
||||
|
||||
@@ -3468,7 +3468,7 @@ void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const cha
|
||||
}
|
||||
}
|
||||
|
||||
void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int max_len)
|
||||
void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int value_maxncpy)
|
||||
{
|
||||
StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop);
|
||||
|
||||
@@ -3477,7 +3477,7 @@ void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int m
|
||||
if (idprop->ui_data) {
|
||||
BLI_assert(idprop->type == IDP_STRING);
|
||||
const IDPropertyUIDataString *ui_data = (const IDPropertyUIDataString *)idprop->ui_data;
|
||||
BLI_strncpy(value, ui_data->default_value, max_len);
|
||||
BLI_strncpy(value, ui_data->default_value, value_maxncpy);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1812,13 +1812,13 @@ static void rna_Operator_bl_label_set(PointerRNA *ptr, const char *value)
|
||||
* so the internal value may be NULL, without allowing Python to assign `None` which doesn't
|
||||
* make any sense in this case.
|
||||
*/
|
||||
# define OPERATOR_STR_MAYBE_NULL_GETSET(attr, len) \
|
||||
# define OPERATOR_STR_MAYBE_NULL_GETSET(attr, attr_maxncpy) \
|
||||
static void rna_Operator_bl_##attr##_set(PointerRNA *ptr, const char *value) \
|
||||
{ \
|
||||
wmOperator *data = (wmOperator *)(ptr->data); \
|
||||
char *str = (char *)data->type->attr; \
|
||||
if (str && !str[0]) { \
|
||||
BLI_strncpy(str, value, len); /* utf8 already ensured */ \
|
||||
BLI_strncpy(str, value, attr_maxncpy); /* utf8 already ensured */ \
|
||||
} \
|
||||
else { \
|
||||
BLI_assert( \
|
||||
|
||||
@@ -86,7 +86,7 @@ int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node);
|
||||
void ntreeCompositCryptomatteLayerPrefix(const Scene *scene,
|
||||
const bNode *node,
|
||||
char *r_prefix,
|
||||
size_t prefix_len);
|
||||
size_t prefix_maxncpy);
|
||||
|
||||
/**
|
||||
* Update the runtime layer names with the crypto-matte layer names of the references render layer
|
||||
|
||||
@@ -192,7 +192,7 @@ void ntreeCompositCryptomatteUpdateLayerNames(const Scene *scene, bNode *node)
|
||||
void ntreeCompositCryptomatteLayerPrefix(const Scene *scene,
|
||||
const bNode *node,
|
||||
char *r_prefix,
|
||||
size_t prefix_len)
|
||||
size_t prefix_maxncpy)
|
||||
{
|
||||
BLI_assert(node->type == CMP_NODE_CRYPTOMATTE);
|
||||
NodeCryptomatte *node_cryptomatte = (NodeCryptomatte *)node->storage;
|
||||
@@ -209,14 +209,14 @@ void ntreeCompositCryptomatteLayerPrefix(const Scene *scene,
|
||||
}
|
||||
|
||||
if (layer_name == node_cryptomatte->layer_name) {
|
||||
BLI_strncpy(r_prefix, node_cryptomatte->layer_name, prefix_len);
|
||||
BLI_strncpy(r_prefix, node_cryptomatte->layer_name, prefix_maxncpy);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *cstr = first_layer_name.c_str();
|
||||
BLI_strncpy(r_prefix, cstr, prefix_len);
|
||||
BLI_strncpy(r_prefix, cstr, prefix_maxncpy);
|
||||
}
|
||||
|
||||
CryptomatteSession *ntreeCompositCryptomatteSession(const Scene *scene, bNode *node)
|
||||
|
||||
Reference in New Issue
Block a user