From df54b627b32907e11d9f6cb8b00499b5f501a82a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 7 May 2023 15:22:58 +1000 Subject: [PATCH] Cleanup: use of the term 'len' & 'maxlen' Only use the term len & maxlen when they represent the length & maximum length of a string. Instead of the available bytes to use. Also include the data they're referencing as a suffix, otherwise it's not always clear what the length is in reference to. --- source/blender/blenkernel/BKE_appdir.h | 9 +- source/blender/blenkernel/BKE_modifier.h | 2 +- source/blender/blenkernel/BKE_node.h | 2 +- source/blender/blenkernel/BKE_unit.h | 16 +- source/blender/blenkernel/intern/appdir.c | 149 +++++++++--------- source/blender/blenkernel/intern/armature.c | 4 +- .../blenkernel/intern/blendfile_link_append.c | 12 +- source/blender/blenkernel/intern/modifier.cc | 4 +- source/blender/blenkernel/intern/node.cc | 8 +- source/blender/blenkernel/intern/unit.c | 122 +++++++------- source/blender/blenlib/BLI_string.h | 8 +- .../blender/blenlib/BLI_string_cursor_utf8.h | 12 +- source/blender/blenlib/intern/string.c | 20 +-- .../blenlib/intern/string_cursor_utf8.c | 64 ++++---- source/blender/editors/animation/drivers.c | 12 +- .../editors/asset/intern/asset_indexer.cc | 4 +- source/blender/editors/include/UI_interface.h | 2 +- source/blender/editors/interface/interface.cc | 83 +++++----- .../editors/interface/interface_anim.cc | 4 +- .../editors/interface/interface_handlers.cc | 43 ++--- .../editors/interface/interface_intern.hh | 10 +- .../editors/interface/interface_ops.cc | 8 +- .../editors/interface/interface_query.cc | 4 +- .../editors/interface/interface_utils.cc | 4 +- source/blender/editors/space_info/textview.c | 6 +- .../blender/editors/space_node/node_select.cc | 6 +- .../editors/space_sequencer/sequencer_draw.c | 18 +-- .../transform/transform_mode_translate.c | 6 +- source/blender/makesrna/intern/rna_internal.h | 6 +- source/blender/makesrna/intern/rna_nodetree.c | 7 +- source/blender/makesrna/intern/rna_object.c | 25 ++- source/blender/makesrna/intern/rna_pose.c | 7 +- .../composite/nodes/node_composite_mask.cc | 6 +- .../nodes/node_composite_moviedistortion.cc | 6 +- .../function/nodes/node_fn_boolean_math.cc | 7 +- .../nodes/function/nodes/node_fn_compare.cc | 7 +- .../function/nodes/node_fn_float_to_int.cc | 7 +- source/blender/nodes/intern/node_common.cc | 8 +- source/blender/nodes/intern/node_common.h | 2 +- source/blender/nodes/intern/node_util.cc | 32 ++-- source/blender/nodes/intern/node_util.hh | 13 +- .../nodes/shader/nodes/node_shader_mix.cc | 4 +- source/blender/python/generic/py_capi_utils.c | 6 +- source/blender/python/generic/py_capi_utils.h | 2 +- .../blender/python/intern/bpy_interface_run.c | 4 +- source/blender/windowmanager/WM_keymap.h | 15 +- .../windowmanager/intern/wm_event_query.c | 10 +- .../windowmanager/intern/wm_event_system.cc | 8 +- .../blender/windowmanager/intern/wm_keymap.c | 30 ++-- 49 files changed, 465 insertions(+), 389 deletions(-) diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index a67c6c27b47..bea163a21d0 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -66,7 +66,7 @@ bool BKE_appdir_folder_documents(char *dir) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES * \returns True if the path is valid. It doesn't create or checks format * if the `blender` folder exists. It does check if the parent of the path exists. */ -bool BKE_appdir_folder_caches(char *r_path, size_t path_len) ATTR_NONNULL(1); +bool BKE_appdir_folder_caches(char *r_path, size_t r_path_maxncpy) ATTR_NONNULL(1); /** * Get a folder out of the \a folder_id presets for paths. * @@ -74,7 +74,10 @@ bool BKE_appdir_folder_caches(char *r_path, size_t path_len) ATTR_NONNULL(1); * this may contain path separators but must resolve to a directory, checked with #BLI_is_dir. * \return The path if found, NULL string if not. */ -bool BKE_appdir_folder_id_ex(int folder_id, const char *subfolder, char *path, size_t path_len); +bool BKE_appdir_folder_id_ex(int folder_id, + const char *subfolder, + char *path, + size_t path_maxncpy); const char *BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT; /** * Returns the path to a folder in the user area, creating it if it doesn't exist. @@ -104,7 +107,7 @@ bool BKE_appdir_app_is_portable_install(void); * Return true if templates exist */ bool BKE_appdir_app_template_any(void); -bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_len) +bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_maxncpy) ATTR_NONNULL(1); bool BKE_appdir_app_template_has_userpref(const char *app_template) ATTR_NONNULL(1); void BKE_appdir_app_templates(struct ListBase *templates) ATTR_NONNULL(1); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 4641cc47b14..5e9d5e38a61 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -556,7 +556,7 @@ void BKE_modifier_mdef_compact_influences(struct ModifierData *md); /** * Initializes `path` with either the blend file or temporary directory. */ -void BKE_modifier_path_init(char *path, int path_maxlen, const char *name); +void BKE_modifier_path_init(char *path, int path_maxncpy, const char *name); const char *BKE_modifier_path_relbase(struct Main *bmain, struct Object *ob); const char *BKE_modifier_path_relbase_from_global(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 3e3766c4ea4..9b1c8c31a2f 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -263,7 +263,7 @@ typedef struct bNodeType { void (*labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, - int maxlen); + int label_maxncpy); /** Optional override for node class, used for drawing node header. */ int (*ui_class)(const struct bNode *node); diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h index f051335fc41..57b26ae6f89 100644 --- a/source/blender/blenkernel/BKE_unit.h +++ b/source/blender/blenkernel/BKE_unit.h @@ -17,14 +17,20 @@ struct UnitSettings; /** * Humanly readable representation of a value in units (used for button drawing). */ -size_t BKE_unit_value_as_string_adaptive( - char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad); +size_t BKE_unit_value_as_string_adaptive(char *str, + int str_maxncpy, + double value, + int prec, + int system, + int type, + bool split, + bool pad); /** * Representation of a value in units. Negative precision is used to disable stripping of zeroes. * This reduces text jumping when changing values. */ size_t BKE_unit_value_as_string(char *str, - int len_max, + int str_maxncpy, double value, int prec, int type, @@ -49,7 +55,7 @@ size_t BKE_unit_value_as_string(char *str, * \return True of a change was made. */ bool BKE_unit_replace_string( - char *str, int len_max, const char *str_prev, double scale_pref, int system, int type); + char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type); /** * \return true if the string contains any valid unit for the given type. @@ -64,7 +70,7 @@ double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int ty /** * Make string keyboard-friendly, e.g: `10µm -> 10um`. */ -void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type); +void BKE_unit_name_to_alt(char *str, int str_maxncpy, const char *orig_str, int system, int type); /** * The size of the unit used for this value (used for calculating the click-step). diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index c7ed3721779..89137143986 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -201,9 +201,9 @@ bool BKE_appdir_folder_documents(char *dir) return true; } -bool BKE_appdir_folder_caches(char *r_path, const size_t path_len) +bool BKE_appdir_folder_caches(char *path, const size_t path_maxncpy) { - r_path[0] = '\0'; + path[0] = '\0'; const char *caches_root_path = GHOST_getUserSpecialDir(GHOST_kUserSpecialDirCaches); if (caches_root_path == NULL || !BLI_is_dir(caches_root_path)) { @@ -215,11 +215,11 @@ bool BKE_appdir_folder_caches(char *r_path, const size_t path_len) #ifdef WIN32 BLI_path_join( - r_path, path_len, caches_root_path, "Blender Foundation", "Blender", "Cache", SEP_STR); + path, path_maxncpy, caches_root_path, "Blender Foundation", "Blender", "Cache", SEP_STR); #elif defined(__APPLE__) - BLI_path_join(r_path, path_len, caches_root_path, "Blender", SEP_STR); + BLI_path_join(path, path_maxncpy, caches_root_path, "Blender", SEP_STR); #else /* __linux__ */ - BLI_path_join(r_path, path_len, caches_root_path, "blender", SEP_STR); + BLI_path_join(path, path_maxncpy, caches_root_path, "blender", SEP_STR); #endif return true; @@ -272,7 +272,7 @@ bool BKE_appdir_font_folder_default(char *dir) * For now usage is limited and we don't need this. */ static bool test_path(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const bool check_is_dir, const char *path_base, const char *folder_name, @@ -284,7 +284,7 @@ static bool test_path(char *targetpath, BLI_assert(!(folder_name == NULL && (subfolder_name != NULL))); const char *path_array[] = {path_base, folder_name, subfolder_name}; const int path_array_num = (folder_name ? (subfolder_name ? 3 : 2) : 1); - BLI_path_join_array(targetpath, targetpath_len, path_array, path_array_num); + BLI_path_join_array(targetpath, targetpath_maxncpy, path_array, path_array_num); if (check_is_dir == false) { CLOG_INFO(&LOG, 3, "using without test: '%s'", targetpath); return true; @@ -353,7 +353,7 @@ static bool test_env_path(char *path, const char *envvar, const bool check_is_di * \return true if such a directory exists. */ static bool get_path_local_ex(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name, const int version, @@ -390,21 +390,21 @@ static bool get_path_local_ex(char *targetpath, path_base = osx_resourses; #endif return test_path(targetpath, - targetpath_len, + targetpath_maxncpy, check_is_dir, path_base, blender_version_decimal(version), relfolder); } static bool get_path_local(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name) { const int version = BLENDER_VERSION; const bool check_is_dir = true; return get_path_local_ex( - targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); } bool BKE_appdir_app_is_portable_install(void) @@ -424,7 +424,7 @@ bool BKE_appdir_app_is_portable_install(void) * \return true if it was able to construct such a path and the path exists. */ static bool get_path_environment_ex(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *subfolder_name, const char *envvar, const bool check_is_dir) @@ -433,17 +433,19 @@ static bool get_path_environment_ex(char *targetpath, if (test_env_path(user_path, envvar, check_is_dir)) { /* Note that `subfolder_name` may be NULL, in this case we use `user_path` as-is. */ - return test_path(targetpath, targetpath_len, check_is_dir, user_path, subfolder_name, NULL); + return test_path( + targetpath, targetpath_maxncpy, check_is_dir, user_path, subfolder_name, NULL); } return false; } static bool get_path_environment(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *subfolder_name, const char *envvar) { const bool check_is_dir = true; - return get_path_environment_ex(targetpath, targetpath_len, subfolder_name, envvar, check_is_dir); + return get_path_environment_ex( + targetpath, targetpath_maxncpy, subfolder_name, envvar, check_is_dir); } /** @@ -457,7 +459,7 @@ static bool get_path_environment(char *targetpath, * \return true if it was able to construct such a path. */ static bool get_path_user_ex(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name, const int version, @@ -472,7 +474,7 @@ static bool get_path_user_ex(char *targetpath, /* for portable install, user path is always local */ if (BKE_appdir_app_is_portable_install()) { return get_path_local_ex( - targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); } user_path[0] = '\0'; @@ -495,17 +497,17 @@ static bool get_path_user_ex(char *targetpath, /* `subfolder_name` may be NULL. */ return test_path( - targetpath, targetpath_len, check_is_dir, user_path, folder_name, subfolder_name); + targetpath, targetpath_maxncpy, check_is_dir, user_path, folder_name, subfolder_name); } static bool get_path_user(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name) { const int version = BLENDER_VERSION; const bool check_is_dir = true; return get_path_user_ex( - targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); } /** @@ -519,7 +521,7 @@ static bool get_path_user(char *targetpath, * \return true if it was able to construct such a path. */ static bool get_path_system_ex(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name, const int version, @@ -561,18 +563,18 @@ static bool get_path_system_ex(char *targetpath, /* Try `$BLENDERPATH/folder_name/subfolder_name`, `subfolder_name` may be NULL. */ return test_path( - targetpath, targetpath_len, check_is_dir, system_path, folder_name, subfolder_name); + targetpath, targetpath_maxncpy, check_is_dir, system_path, folder_name, subfolder_name); } static bool get_path_system(char *targetpath, - size_t targetpath_len, + size_t targetpath_maxncpy, const char *folder_name, const char *subfolder_name) { const int version = BLENDER_VERSION; const bool check_is_dir = true; return get_path_system_ex( - targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); } /** \} */ @@ -584,95 +586,95 @@ static bool get_path_system(char *targetpath, bool BKE_appdir_folder_id_ex(const int folder_id, const char *subfolder, char *path, - size_t path_len) + size_t path_maxncpy) { switch (folder_id) { case BLENDER_DATAFILES: /* general case */ - if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_DATAFILES")) { break; } - if (get_path_user(path, path_len, "datafiles", subfolder)) { + if (get_path_user(path, path_maxncpy, "datafiles", subfolder)) { break; } - if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_DATAFILES")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_SYSTEM_DATAFILES")) { break; } - if (get_path_local(path, path_len, "datafiles", subfolder)) { + if (get_path_local(path, path_maxncpy, "datafiles", subfolder)) { break; } - if (get_path_system(path, path_len, "datafiles", subfolder)) { + if (get_path_system(path, path_maxncpy, "datafiles", subfolder)) { break; } return false; case BLENDER_USER_DATAFILES: - if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_DATAFILES")) { break; } - if (get_path_user(path, path_len, "datafiles", subfolder)) { + if (get_path_user(path, path_maxncpy, "datafiles", subfolder)) { break; } return false; case BLENDER_SYSTEM_DATAFILES: - if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_DATAFILES")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_SYSTEM_DATAFILES")) { break; } - if (get_path_system(path, path_len, "datafiles", subfolder)) { + if (get_path_system(path, path_maxncpy, "datafiles", subfolder)) { break; } - if (get_path_local(path, path_len, "datafiles", subfolder)) { + if (get_path_local(path, path_maxncpy, "datafiles", subfolder)) { break; } return false; case BLENDER_USER_AUTOSAVE: - if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_DATAFILES")) { break; } - if (get_path_user(path, path_len, "autosave", subfolder)) { + if (get_path_user(path, path_maxncpy, "autosave", subfolder)) { break; } return false; case BLENDER_USER_CONFIG: - if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_CONFIG")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_CONFIG")) { break; } - if (get_path_user(path, path_len, "config", subfolder)) { + if (get_path_user(path, path_maxncpy, "config", subfolder)) { break; } return false; case BLENDER_USER_SCRIPTS: - if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_SCRIPTS")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_SCRIPTS")) { break; } - if (get_path_user(path, path_len, "scripts", subfolder)) { + if (get_path_user(path, path_maxncpy, "scripts", subfolder)) { break; } return false; case BLENDER_SYSTEM_SCRIPTS: - if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_SCRIPTS")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_SYSTEM_SCRIPTS")) { break; } - if (get_path_system(path, path_len, "scripts", subfolder)) { + if (get_path_system(path, path_maxncpy, "scripts", subfolder)) { break; } - if (get_path_local(path, path_len, "scripts", subfolder)) { + if (get_path_local(path, path_maxncpy, "scripts", subfolder)) { break; } return false; case BLENDER_SYSTEM_PYTHON: - if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_PYTHON")) { + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_SYSTEM_PYTHON")) { break; } - if (get_path_system(path, path_len, "python", subfolder)) { + if (get_path_system(path, path_maxncpy, "python", subfolder)) { break; } - if (get_path_local(path, path_len, "python", subfolder)) { + if (get_path_local(path, path_maxncpy, "python", subfolder)) { break; } return false; @@ -818,7 +820,9 @@ const char *BKE_appdir_resource_path_id(const int folder_id, const bool check_is * (must be #FILE_MAX minimum) * \param name: The name of the executable (usually `argv[0]`) to be checked */ -static void where_am_i(char *program_filepath, const size_t maxlen, const char *program_name) +static void where_am_i(char *program_filepath, + const size_t program_filepath_maxncpy, + const char *program_name) { # ifdef WITH_BINRELOC /* Linux uses `binreloc` since `argv[0]` is not reliable, call `br_init(NULL)` first. */ @@ -826,7 +830,7 @@ static void where_am_i(char *program_filepath, const size_t maxlen, const char * const char *path = NULL; path = br_find_exe(NULL); if (path) { - BLI_strncpy(program_filepath, path, maxlen); + BLI_strncpy(program_filepath, path, program_filepath_maxncpy); free((void *)path); return; } @@ -835,11 +839,14 @@ static void where_am_i(char *program_filepath, const size_t maxlen, const char * # ifdef _WIN32 { - wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); - if (GetModuleFileNameW(0, fullname_16, maxlen)) { - conv_utf_16_to_8(fullname_16, program_filepath, maxlen); + wchar_t *fullname_16 = MEM_mallocN(program_filepath_maxncpy * sizeof(wchar_t), "ProgramPath"); + if (GetModuleFileNameW(0, fullname_16, program_filepath_maxncpy)) { + conv_utf_16_to_8(fullname_16, program_filepath, program_filepath_maxncpy); if (!BLI_exists(program_filepath)) { - CLOG_ERROR(&LOG, "path can't be found: \"%.*s\"", (int)maxlen, program_filepath); + CLOG_ERROR(&LOG, + "path can't be found: \"%.*s\"", + (int)program_filepath_maxncpy, + program_filepath); MessageBox( NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } @@ -854,22 +861,22 @@ static void where_am_i(char *program_filepath, const size_t maxlen, const char * /* Unix and non Linux. */ if (program_name && program_name[0]) { - BLI_strncpy(program_filepath, program_name, maxlen); + BLI_strncpy(program_filepath, program_name, program_filepath_maxncpy); if (program_name[0] == '.') { - BLI_path_abs_from_cwd(program_filepath, maxlen); + BLI_path_abs_from_cwd(program_filepath, program_filepath_maxncpy); # ifdef _WIN32 - BLI_path_program_extensions_add_win32(program_filepath, maxlen); + BLI_path_program_extensions_add_win32(program_filepath, program_filepath_maxncpy); # endif } else if (BLI_path_slash_rfind(program_name)) { /* Full path. */ - BLI_strncpy(program_filepath, program_name, maxlen); + BLI_strncpy(program_filepath, program_name, program_filepath_maxncpy); # ifdef _WIN32 - BLI_path_program_extensions_add_win32(program_filepath, maxlen); + BLI_path_program_extensions_add_win32(program_filepath, program_filepath_maxncpy); # endif } else { - BLI_path_program_search(program_filepath, maxlen, program_name); + BLI_path_program_search(program_filepath, program_filepath_maxncpy, program_name); } /* Remove "/./" and "/../" so string comparisons can be used on the path. */ BLI_path_normalize(program_filepath); @@ -1024,12 +1031,12 @@ bool BKE_appdir_app_template_any(void) return false; } -bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_len) +bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_maxncpy) { for (int i = 0; i < ARRAY_SIZE(app_template_directory_id); i++) { char subdir[FILE_MAX]; BLI_path_join(subdir, sizeof(subdir), app_template_directory_search[i], app_template); - if (BKE_appdir_folder_id_ex(app_template_directory_id[i], subdir, path, path_len)) { + if (BKE_appdir_folder_id_ex(app_template_directory_id[i], subdir, path, path_maxncpy)) { return true; } } @@ -1095,27 +1102,27 @@ void BKE_appdir_app_templates(ListBase *templates) * Also make sure the temp dir has a trailing slash * * \param tempdir: The full path to the temporary temp directory. - * \param tempdir_maxlen: The size of the \a tempdir buffer. + * \param tempdir_maxncpy: The size of the \a tempdir buffer. * \param userdir: Directory specified in user preferences (may be NULL). * note that by default this is an empty string, only use when non-empty. */ -static void where_is_temp(char *tempdir, const size_t tempdir_maxlen, const char *userdir) +static void where_is_temp(char *tempdir, const size_t tempdir_maxncpy, const char *userdir) { tempdir[0] = '\0'; if (userdir && userdir[0] != '\0' && BLI_is_dir(userdir)) { - BLI_strncpy(tempdir, userdir, tempdir_maxlen); + BLI_strncpy(tempdir, userdir, tempdir_maxncpy); /* Add a trailing slash if needed. */ - BLI_path_slash_ensure(tempdir, tempdir_maxlen); + BLI_path_slash_ensure(tempdir, tempdir_maxncpy); return; } - BLI_temp_directory_path_get(tempdir, tempdir_maxlen); + BLI_temp_directory_path_get(tempdir, tempdir_maxncpy); } static void tempdir_session_create(char *tempdir_session, - const size_t tempdir_session_maxlen, + const size_t tempdir_session_maxncpy, const char *tempdir) { tempdir_session[0] = '\0'; @@ -1129,9 +1136,9 @@ static void tempdir_session_create(char *tempdir_session, * #_mktemp_s also requires the last null character is included. */ const int tempdir_session_len_required = tempdir_len + session_name_len + 1; - if (tempdir_session_len_required <= tempdir_session_maxlen) { + if (tempdir_session_len_required <= tempdir_session_maxncpy) { /* No need to use path joining utility as we know the last character of #tempdir is a slash. */ - BLI_string_join(tempdir_session, tempdir_session_maxlen, tempdir, session_name); + BLI_string_join(tempdir_session, tempdir_session_maxncpy, tempdir, session_name); #ifdef WIN32 const bool needs_create = (_mktemp_s(tempdir_session, tempdir_session_len_required) == 0); #else @@ -1141,7 +1148,7 @@ static void tempdir_session_create(char *tempdir_session, BLI_dir_create_recursive(tempdir_session); } if (BLI_is_dir(tempdir_session)) { - BLI_path_slash_ensure(tempdir_session, tempdir_session_maxlen); + BLI_path_slash_ensure(tempdir_session, tempdir_session_maxncpy); /* Success. */ return; } @@ -1151,7 +1158,7 @@ static void tempdir_session_create(char *tempdir_session, "Could not generate a temp file name for '%s', falling back to '%s'", tempdir_session, tempdir); - BLI_strncpy(tempdir_session, tempdir, tempdir_session_maxlen); + BLI_strncpy(tempdir_session, tempdir, tempdir_session_maxncpy); } void BKE_tempdir_init(const char *userdir) diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index fe2d8af8da7..1a3699bb7af 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -816,8 +816,8 @@ bool bone_autoside_name( } /* Subtract 1 from #MAXBONENAME for the null byte. Add 1 to the extension for the '.' */ - const int basename_maxlen = (MAXBONENAME - 1) - (1 + strlen(extension)); - BLI_snprintf(name, MAXBONENAME, "%.*s.%s", basename_maxlen, basename, extension); + const int basename_maxncpy = (MAXBONENAME - 1) - (1 + strlen(extension)); + BLI_snprintf(name, MAXBONENAME, "%.*s.%s", basename_maxncpy, basename, extension); return true; } diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c b/source/blender/blenkernel/intern/blendfile_link_append.c index 8b5a3131cfb..eacfbde6b9d 100644 --- a/source/blender/blenkernel/intern/blendfile_link_append.c +++ b/source/blender/blenkernel/intern/blendfile_link_append.c @@ -243,9 +243,9 @@ void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *l BlendfileLinkAppendContextLibrary *lib_context = BLI_memarena_calloc(lapp_context->memarena, sizeof(*lib_context)); - size_t len = strlen(libname) + 1; - char *libpath = BLI_memarena_alloc(lapp_context->memarena, len); - BLI_strncpy(libpath, libname, len); + const size_t libname_size = strlen(libname) + 1; + char *libpath = BLI_memarena_alloc(lapp_context->memarena, libname_size); + BLI_strncpy(libpath, libname, libname_size); lib_context->path = libpath; lib_context->blo_handle = blo_handle; @@ -263,10 +263,10 @@ BlendfileLinkAppendContextItem *BKE_blendfile_link_append_context_item_add( { BlendfileLinkAppendContextItem *item = BLI_memarena_calloc(lapp_context->memarena, sizeof(*item)); - size_t len = strlen(idname) + 1; + const size_t idname_size = strlen(idname) + 1; - item->name = BLI_memarena_alloc(lapp_context->memarena, len); - BLI_strncpy(item->name, idname, len); + item->name = BLI_memarena_alloc(lapp_context->memarena, idname_size); + BLI_strncpy(item->name, idname, idname_size); item->idcode = idcode; item->libraries = BLI_BITMAP_NEW_MEMARENA(lapp_context->memarena, lapp_context->num_libraries); diff --git a/source/blender/blenkernel/intern/modifier.cc b/source/blender/blenkernel/intern/modifier.cc index d5f3565744c..15baafbc166 100644 --- a/source/blender/blenkernel/intern/modifier.cc +++ b/source/blender/blenkernel/intern/modifier.cc @@ -954,10 +954,10 @@ const char *BKE_modifier_path_relbase_from_global(Object *ob) return BKE_modifier_path_relbase(G_MAIN, ob); } -void BKE_modifier_path_init(char *path, int path_maxlen, const char *name) +void BKE_modifier_path_init(char *path, int path_maxncpy, const char *name) { const char *blendfile_path = BKE_main_blendfile_path_from_global(); - BLI_path_join(path, path_maxlen, blendfile_path[0] ? "//" : BKE_tempdir_session(), name); + BLI_path_join(path, path_maxncpy, blendfile_path[0] ? "//" : BKE_tempdir_session(), name); } /** diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index af6ef9e2982..abee776bceb 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4095,15 +4095,15 @@ void ntreeUpdateAllUsers(Main *main, ID *id) /* ************* node type access ********** */ -void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, const int maxlen) +void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, const int label_maxncpy) { label[0] = '\0'; if (node->label[0] != '\0') { - BLI_strncpy(label, node->label, maxlen); + BLI_strncpy(label, node->label, label_maxncpy); } else if (node->typeinfo->labelfunc) { - node->typeinfo->labelfunc(ntree, node, label, maxlen); + node->typeinfo->labelfunc(ntree, node, label, label_maxncpy); } if (label[0] != '\0') { /* The previous methods (labelfunc) could not provide an adequate label for the node. */ @@ -4115,7 +4115,7 @@ void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, const int if (tmp == node->typeinfo->ui_name) { tmp = IFACE_(node->typeinfo->ui_name); } - BLI_strncpy(label, tmp, maxlen); + BLI_strncpy(label, tmp, label_maxncpy); } const char *nodeSocketLabel(const bNodeSocket *sock) diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index e5f64df3741..fbdb7d171cb 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -441,7 +441,7 @@ static void unit_dual_convert(double value, } static size_t unit_as_string(char *str, - int len_max, + int str_maxncpy, double value, int prec, const bUnitCollection *usys, @@ -477,7 +477,7 @@ static size_t unit_as_string(char *str, CLAMP(prec, 0, 6); /* Convert to a string. */ - size_t len = BLI_snprintf_rlen(str, len_max, "%.*f", prec, value_conv); + size_t len = BLI_snprintf_rlen(str, str_maxncpy, "%.*f", prec, value_conv); /* Add unit prefix and strip zeros. */ @@ -504,17 +504,17 @@ static size_t unit_as_string(char *str, } /* Now add the suffix. */ - if (i < len_max) { + if (i < str_maxncpy) { int j = 0; i++; - while (unit->name_short[j] && (i < len_max)) { + while (unit->name_short[j] && (i < str_maxncpy)) { str[i++] = unit->name_short[j++]; } } /* Terminate no matter what's done with padding above. */ - if (i >= len_max) { - i = len_max - 1; + if (i >= str_maxncpy) { + i = str_maxncpy - 1; } str[i] = '\0'; @@ -549,7 +549,7 @@ static PreferredUnits preferred_units_from_UnitSettings(const UnitSettings *sett } static size_t unit_as_string_split_pair(char *str, - int len_max, + int str_maxncpy, double value, int prec, const bUnitCollection *usys, @@ -561,18 +561,18 @@ static size_t unit_as_string_split_pair(char *str, /* Check the 2 is a smaller unit. */ if (unit_b > unit_a) { - size_t i = unit_as_string(str, len_max, value_a, prec, usys, unit_a, '\0'); + size_t i = unit_as_string(str, str_maxncpy, value_a, prec, usys, unit_a, '\0'); prec -= integer_digits_d(value_a / unit_b->scalar) - integer_digits_d(value_b / unit_b->scalar); prec = max_ii(prec, 0); /* Is there enough space for at least 1 char of the next unit? */ - if (i + 2 < len_max) { + if (i + 2 < str_maxncpy) { str[i++] = ' '; /* Use low precision since this is a smaller unit. */ - i += unit_as_string(str + i, len_max - i, value_b, prec, usys, unit_b, '\0'); + i += unit_as_string(str + i, str_maxncpy - i, value_b, prec, usys, unit_b, '\0'); } return i; } @@ -633,7 +633,7 @@ static const bUnitDef *get_preferred_display_unit_if_used(int type, PreferredUni /* Return the length of the generated string. */ static size_t unit_as_string_main(char *str, - int len_max, + int str_maxncpy, double value, int prec, int type, @@ -652,18 +652,18 @@ static size_t unit_as_string_main(char *str, } if (split && unit_should_be_split(type)) { - int length = unit_as_string_split_pair(str, len_max, value, prec, usys, main_unit); + int length = unit_as_string_split_pair(str, str_maxncpy, value, prec, usys, main_unit); /* Failed when length is negative, fallback to no split. */ if (length >= 0) { return length; } } - return unit_as_string(str, len_max, value, prec, usys, main_unit, pad ? ' ' : '\0'); + return unit_as_string(str, str_maxncpy, value, prec, usys, main_unit, pad ? ' ' : '\0'); } size_t BKE_unit_value_as_string_adaptive( - char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad) + char *str, int str_maxncpy, double value, int prec, int system, int type, bool split, bool pad) { PreferredUnits units; units.system = system; @@ -672,11 +672,11 @@ size_t BKE_unit_value_as_string_adaptive( units.mass = USER_UNIT_ADAPTIVE; units.time = USER_UNIT_ADAPTIVE; units.temperature = USER_UNIT_ADAPTIVE; - return unit_as_string_main(str, len_max, value, prec, type, split, pad, units); + return unit_as_string_main(str, str_maxncpy, value, prec, type, split, pad, units); } size_t BKE_unit_value_as_string(char *str, - int len_max, + int str_maxncpy, double value, int prec, int type, @@ -685,7 +685,7 @@ size_t BKE_unit_value_as_string(char *str, { bool do_split = (settings->flag & USER_UNIT_OPT_SPLIT) != 0; PreferredUnits units = preferred_units_from_UnitSettings(settings); - return unit_as_string_main(str, len_max, value, prec, type, do_split, pad, units); + return unit_as_string_main(str, str_maxncpy, value, prec, type, do_split, pad, units); } BLI_INLINE bool isalpha_or_utf8(const int ch) @@ -800,10 +800,10 @@ static char *find_next_negative(const char *str, const char *remaining_str) * \note This unnecessarily skips the space before the operation character * just to make a more predictable output. */ -static char *find_next_op(const char *str, char *remaining_str, int len_max) +static char *find_next_op(const char *str, char *remaining_str, int remaining_str_maxncpy) { int i; - for (i = 0; i < len_max; i++) { + for (i = 0; i < remaining_str_maxncpy; i++) { if (remaining_str[i] == '\0') { return remaining_str + i; } @@ -842,29 +842,29 @@ static char *find_next_op(const char *str, char *remaining_str, int len_max) * * "-1m50cm + 1 - 2m50cm" -> "-(1m50cm) + 1 - (2m50cm)" */ -static bool unit_distribute_negatives(char *str, const int len_max) +static bool unit_distribute_negatives(char *str, const int str_maxncpy) { bool changed = false; char *remaining_str = str; while ((remaining_str = find_next_negative(str, remaining_str)) != NULL) { - int remaining_str_len; + int remaining_str_maxncpy; /* Exit early in the unlikely situation that we've run out of length to add the parentheses. */ - remaining_str_len = len_max - (int)(remaining_str - str); - if (remaining_str_len <= 2) { + remaining_str_maxncpy = str_maxncpy - (int)(remaining_str - str); + if (remaining_str_maxncpy <= 2) { return changed; } changed = true; /* Add '(', shift the following characters to the right to make space. */ - memmove(remaining_str + 1, remaining_str, remaining_str_len - 2); + memmove(remaining_str + 1, remaining_str, remaining_str_maxncpy - 2); *remaining_str = '('; /* Add the ')' before the next operation or at the end. */ - remaining_str = find_next_op(str, remaining_str + 1, remaining_str_len); - remaining_str_len = len_max - (int)(remaining_str - str); - memmove(remaining_str + 1, remaining_str, remaining_str_len - 2); + remaining_str = find_next_op(str, remaining_str + 1, remaining_str_maxncpy); + remaining_str_maxncpy = str_maxncpy - (int)(remaining_str - str); + memmove(remaining_str + 1, remaining_str, remaining_str_maxncpy - 2); *remaining_str = ')'; /* Only move forward by 1 even though we added two characters. Minus signs need to be able to @@ -893,10 +893,10 @@ static int find_previous_non_value_char(const char *str, const int start_ofs) * Helper for #unit_scale_str for the process of correctly applying the order of operations * for the unit's bias term. */ -static int find_end_of_value_chars(const char *str, const int len_max, const int start_ofs) +static int find_end_of_value_chars(const char *str, const int str_maxncpy, const int start_ofs) { int i; - for (i = start_ofs; i < len_max; i++) { + for (i = start_ofs; i < str_maxncpy; i++) { if (!strchr("0123456789eE.", str[i])) { return i; } @@ -905,18 +905,18 @@ static int find_end_of_value_chars(const char *str, const int len_max, const int } static int unit_scale_str(char *str, - int len_max, + int str_maxncpy, char *str_tmp, double scale_pref, const bUnitDef *unit, const char *replace_str, bool case_sensitive) { - if (len_max < 0) { + if (str_maxncpy < 0) { return 0; } - /* XXX: investigate, does not respect len_max properly. */ + /* XXX: investigate, does not respect str_maxncpy properly. */ char *str_found = (char *)unit_find_str(str, replace_str, case_sensitive); if (str_found == NULL) { @@ -935,7 +935,7 @@ static int unit_scale_str(char *str, if (unit->bias != 0.0) { /* Add the open parenthesis. */ int prev_op_ofs = find_previous_non_value_char(str, found_ofs); - if (len + 1 < len_max) { + if (len + 1 < str_maxncpy) { memmove(str + prev_op_ofs + 1, str + prev_op_ofs, len - prev_op_ofs + 1); str[prev_op_ofs] = '('; len++; @@ -944,9 +944,9 @@ static int unit_scale_str(char *str, } /* If this doesn't fit, we have failed. */ /* Add the addition sign, the bias, and the close parenthesis after the value. */ - int value_end_ofs = find_end_of_value_chars(str, len_max, prev_op_ofs + 2); + int value_end_ofs = find_end_of_value_chars(str, str_maxncpy, prev_op_ofs + 2); int len_bias_num = BLI_snprintf_rlen(str_tmp, TEMP_STR_SIZE, "+%.9g)", unit->bias); - if (value_end_ofs + len_bias_num < len_max) { + if (value_end_ofs + len_bias_num < str_maxncpy) { memmove(str + value_end_ofs + len_bias_num, str + value_end_ofs, len - value_end_ofs + 1); memcpy(str + value_end_ofs, str_tmp, len_bias_num); len += len_bias_num; @@ -962,13 +962,13 @@ static int unit_scale_str(char *str, int len_num = BLI_snprintf_rlen( str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref); - if (len_num > len_max) { - len_num = len_max; + if (len_num > str_maxncpy) { + len_num = str_maxncpy; } - if (found_ofs + len_num + len_move > len_max) { + if (found_ofs + len_num + len_move > str_maxncpy) { /* Can't move the whole string, move just as much as will fit. */ - len_move -= (found_ofs + len_num + len_move) - len_max; + len_move -= (found_ofs + len_num + len_move) - str_maxncpy; } if (len_move > 0) { @@ -977,9 +977,9 @@ static int unit_scale_str(char *str, memmove(str_found + len_num, str_found + len_name, len_move); } - if (found_ofs + len_num > len_max) { + if (found_ofs + len_num > str_maxncpy) { /* Not even the number will fit into the string, only copy part of it. */ - len_num -= (found_ofs + len_num) - len_max; + len_num -= (found_ofs + len_num) - str_maxncpy; } if (len_num > 0) { @@ -989,22 +989,23 @@ static int unit_scale_str(char *str, /* Since the null terminator won't be moved if the stringlen_max * was not long enough to fit everything in it. */ - str[len_max - 1] = '\0'; + str[str_maxncpy - 1] = '\0'; return found_ofs + len_num; } static int unit_replace( - char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit) + char *str, int str_maxncpy, char *str_tmp, double scale_pref, const bUnitDef *unit) { const bool case_sensitive = (unit->flag & B_UNIT_DEF_CASE_SENSITIVE) != 0; int ofs = 0; ofs += unit_scale_str( - str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->name_short, case_sensitive); + str + ofs, str_maxncpy - ofs, str_tmp, scale_pref, unit, unit->name_short, case_sensitive); ofs += unit_scale_str( - str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->name_plural, false); + str + ofs, str_maxncpy - ofs, str_tmp, scale_pref, unit, unit->name_plural, false); ofs += unit_scale_str( - str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->name_alt, case_sensitive); - ofs += unit_scale_str(str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->name, false); + str + ofs, str_maxncpy - ofs, str_tmp, scale_pref, unit, unit->name_alt, case_sensitive); + ofs += unit_scale_str( + str + ofs, str_maxncpy - ofs, str_tmp, scale_pref, unit, unit->name, false); return ofs; } @@ -1088,7 +1089,7 @@ double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int ty } bool BKE_unit_replace_string( - char *str, int len_max, const char *str_prev, double scale_pref, int system, int type) + char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type) { const bUnitCollection *usys = unit_get_system(system, type); if (!is_valid_unit_collection(usys)) { @@ -1100,7 +1101,7 @@ bool BKE_unit_replace_string( bool changed = false; /* Fix cases like "-1m50cm" which would evaluate to -0.5m without this. */ - changed |= unit_distribute_negatives(str, len_max); + changed |= unit_distribute_negatives(str, str_maxncpy); /* Try to find a default unit from current or previous string. */ const bUnitDef *default_unit = unit_detect_from_str(usys, str, str_prev); @@ -1114,7 +1115,7 @@ bool BKE_unit_replace_string( if (BLI_snprintf(str_tmp, sizeof(str_tmp), "(%s)*%.9g", str, default_unit->scalar) < sizeof(str_tmp)) { - strncpy(str, str_tmp, len_max); + strncpy(str, str_tmp, str_maxncpy); } else { /* BLI_snprintf would not fit into str_tmp, can't do much in this case. @@ -1124,7 +1125,7 @@ bool BKE_unit_replace_string( for (const bUnitDef *unit = usys->units; unit->name; unit++) { /* In case there are multiple instances. */ - while (unit_replace(str, len_max, str_tmp, scale_pref_base, unit)) { + while (unit_replace(str, str_maxncpy, str_tmp, scale_pref_base, unit)) { changed = true; } } @@ -1141,7 +1142,8 @@ bool BKE_unit_replace_string( for (const bUnitDef *unit = usys_iter->units; unit->name; unit++) { int ofs = 0; /* In case there are multiple instances. */ - while ((ofs = unit_replace(str + ofs, len_max - ofs, str_tmp, scale_pref_base, unit))) { + while ( + (ofs = unit_replace(str + ofs, str_maxncpy - ofs, str_tmp, scale_pref_base, unit))) { changed = true; } } @@ -1176,13 +1178,13 @@ bool BKE_unit_replace_string( return changed; } -void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type) +void BKE_unit_name_to_alt(char *str, int str_maxncpy, const char *orig_str, int system, int type) { const bUnitCollection *usys = unit_get_system(system, type); /* Find and substitute all units. */ for (const bUnitDef *unit = usys->units; unit->name; unit++) { - if (len_max > 0 && unit->name_alt) { + if (str_maxncpy > 0 && unit->name_alt) { const bool case_sensitive = (unit->flag & B_UNIT_DEF_CASE_SENSITIVE) != 0; const char *found = unit_find_str(orig_str, unit->name_short, case_sensitive); if (found) { @@ -1190,30 +1192,30 @@ void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int syst int len_name = 0; /* Copy everything before the unit. */ - offset = (offset < len_max ? offset : len_max); + offset = (offset < str_maxncpy ? offset : str_maxncpy); strncpy(str, orig_str, offset); str += offset; orig_str += offset + strlen(unit->name_short); - len_max -= offset; + str_maxncpy -= offset; /* Print the alt_name. */ if (unit->name_alt) { - len_name = BLI_strncpy_rlen(str, unit->name_alt, len_max); + len_name = BLI_strncpy_rlen(str, unit->name_alt, str_maxncpy); } else { len_name = 0; } - len_name = (len_name < len_max ? len_name : len_max); + len_name = (len_name < str_maxncpy ? len_name : str_maxncpy); str += len_name; - len_max -= len_name; + str_maxncpy -= len_name; } } } /* Finally copy the rest of the string. */ - strncpy(str, orig_str, len_max); + strncpy(str, orig_str, str_maxncpy); } double BKE_unit_closest_scalar(double value, int system, int type) diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index b791dd22531..5df6ef04849 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -142,7 +142,7 @@ char *BLI_str_quoted_substrN(const char *__restrict str, * \param str: is the entire string to chop. * \param prefix: is the part of the string to step over. * \param result: The buffer to fill. - * \param result_maxlen: The maximum size of the buffer (including nil terminator). + * \param result_maxncpy: The maximum size of the buffer (including nil terminator). * \return True if the prefix was found and the entire quoted string was copied into result. * * Assume that the strings returned must be freed afterwards, @@ -151,7 +151,7 @@ char *BLI_str_quoted_substrN(const char *__restrict str, bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, - size_t result_maxlen); + size_t result_maxncpy); /** * string with all instances of substr_old replaced with substr_new, * Returns a copy of the c-string \a str into a newly #MEM_mallocN'd @@ -522,14 +522,14 @@ bool BLI_string_all_words_matched(const char *name, * Find the ranges needed to split \a str into its individual words. * * \param str: The string to search for words. - * \param len: Size of the string to search. + * \param str_maxlen: Size of the string to search (ignored when larger than `strlen(str)`). * \param delim: Character to use as a delimiter. * \param r_words: Info about the words found. Set to [index, len] pairs. * \param words_max: Max number of words to find * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - size_t len, + size_t str_maxlen, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 4); diff --git a/source/blender/blenlib/BLI_string_cursor_utf8.h b/source/blender/blenlib/BLI_string_cursor_utf8.h index 249bd7112c5..8fa0c4ec83f 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -22,21 +22,21 @@ typedef enum eStrCursorJumpDirection { STRCUR_DIR_NEXT, } eStrCursorJumpDirection; -bool BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos); -bool BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos); +bool BLI_str_cursor_step_next_utf8(const char *str, size_t str_maxlen, int *pos); +bool BLI_str_cursor_step_prev_utf8(const char *str, size_t str_maxlen, int *pos); -bool BLI_str_cursor_step_next_utf32(const char32_t *str, size_t maxlen, int *pos); -bool BLI_str_cursor_step_prev_utf32(const char32_t *str, size_t maxlen, int *pos); +bool BLI_str_cursor_step_next_utf32(const char32_t *str, size_t str_maxlen, int *pos); +bool BLI_str_cursor_step_prev_utf32(const char32_t *str, size_t str_maxlen, int *pos); void BLI_str_cursor_step_utf8(const char *str, - size_t maxlen, + size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step); void BLI_str_cursor_step_utf32(const char32_t *str, - size_t maxlen, + size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 22595b816af..04ba5f5a0df 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -534,15 +534,15 @@ void BLI_str_replace_char(char *str, char src, char dst) } bool BLI_str_replace_table_exact(char *string, - const size_t string_len, + const size_t string_maxncpy, const char *replace_table[][2], int replace_table_len) { - BLI_string_debug_size_after_nil(string, string_len); + BLI_string_debug_size_after_nil(string, string_maxncpy); for (int i = 0; i < replace_table_len; i++) { if (STREQ(string, replace_table[i][0])) { - BLI_strncpy(string, replace_table[i][1], string_len); + BLI_strncpy(string, replace_table[i][1], string_maxncpy); return true; } } @@ -1072,19 +1072,19 @@ size_t BLI_str_partition_ex(const char *str, } int BLI_string_find_split_words( - const char *str, const size_t len, const char delim, int r_words[][2], int words_max) + const char *str, const size_t str_maxlen, const char delim, int r_words[][2], int words_max) { int n = 0, i; bool charsearch = true; /* Skip leading spaces */ - for (i = 0; (i < len) && (str[i] != '\0'); i++) { + for (i = 0; (i < str_maxlen) && (str[i] != '\0'); i++) { if (str[i] != delim) { break; } } - for (; (i < len) && (str[i] != '\0') && (n < words_max); i++) { + for (; (i < str_maxlen) && (str[i] != '\0') && (n < words_max); i++) { if ((str[i] != delim) && (charsearch == true)) { r_words[n][0] = i; charsearch = false; @@ -1250,12 +1250,12 @@ void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE * \{ */ #ifdef WITH_STRSIZE_DEBUG -void BLI_string_debug_size_after_nil(char *str, size_t str_maxlen) +void BLI_string_debug_size_after_nil(char *str, size_t str_maxncpy) { /* Step over the nil, into the character afterwards. */ - size_t str_tail = BLI_strnlen(str, str_maxlen) + 2; - if (str_tail < str_maxlen) { - BLI_string_debug_size(str + str_tail, str_maxlen - str_tail); + size_t str_tail = BLI_strnlen(str, str_maxncpy) + 2; + if (str_tail < str_maxncpy) { + BLI_string_debug_size(str + str_tail, str_maxncpy - str_tail); } } diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index b2f759bd37f..95442caa655 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -96,32 +96,32 @@ static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8, return cursor_delim_type_unicode(uch); } -bool BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos) +bool BLI_str_cursor_step_next_utf8(const char *str, size_t str_maxlen, int *pos) { /* NOTE: Keep in sync with #BLI_str_cursor_step_next_utf32. */ - if ((*pos) >= (int)maxlen) { + if ((*pos) >= (int)str_maxlen) { return false; } - const char *str_end = str + (maxlen + 1); + const char *str_end = str + (str_maxlen + 1); const char *str_pos = str + (*pos); const char *str_next = str_pos; do { str_next = BLI_str_find_next_char_utf8(str_next, str_end); } while (str_next < str_end && str_next[0] != 0 && BLI_str_utf8_char_width(str_next) < 1); (*pos) += (str_next - str_pos); - if ((*pos) > (int)maxlen) { - (*pos) = (int)maxlen; + if ((*pos) > (int)str_maxlen) { + (*pos) = (int)str_maxlen; } return true; } -bool BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos) +bool BLI_str_cursor_step_prev_utf8(const char *str, size_t str_maxlen, int *pos) { /* NOTE: Keep in sync with #BLI_str_cursor_step_prev_utf32. */ - if ((*pos) > 0 && (*pos) <= maxlen) { + if ((*pos) > 0 && (*pos) <= str_maxlen) { const char *str_pos = str + (*pos); const char *str_prev = str_pos; do { @@ -135,7 +135,7 @@ bool BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos) } void BLI_str_cursor_step_utf8(const char *str, - size_t maxlen, + size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, @@ -145,26 +145,26 @@ void BLI_str_cursor_step_utf8(const char *str, if (direction == STRCUR_DIR_NEXT) { if (use_init_step) { - BLI_str_cursor_step_next_utf8(str, maxlen, pos); + BLI_str_cursor_step_next_utf8(str, str_maxlen, pos); } else { BLI_assert(jump == STRCUR_JUMP_DELIM); } if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) < maxlen ? - cursor_delim_type_utf8(str, maxlen, *pos) : + const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? + cursor_delim_type_utf8(str, str_maxlen, *pos) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete * list of special character, ctr -> */ - while ((*pos) < maxlen) { - if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { - if (*pos == maxlen) { + while ((*pos) < str_maxlen) { + if (BLI_str_cursor_step_next_utf8(str, str_maxlen, pos)) { + if (*pos == str_maxlen) { break; } if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_utf8(str, maxlen, *pos))) { + (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { break; } } @@ -176,24 +176,24 @@ void BLI_str_cursor_step_utf8(const char *str, } else if (direction == STRCUR_DIR_PREV) { if (use_init_step) { - BLI_str_cursor_step_prev_utf8(str, maxlen, pos); + BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos); } else { BLI_assert(jump == STRCUR_JUMP_DELIM); } if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) > 0 ? - cursor_delim_type_utf8(str, maxlen, *pos - 1) : - STRCUR_DELIM_NONE; + const eStrCursorDelimType delim_type = (*pos) > 0 ? cursor_delim_type_utf8( + str, str_maxlen, *pos - 1) : + STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete * list of special character, ctr -> */ while ((*pos) > 0) { const int pos_prev = *pos; - if (BLI_str_cursor_step_prev_utf8(str, maxlen, pos)) { + if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) { if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_utf8(str, maxlen, *pos))) { + (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { /* left only: compensate for index/change in direction */ if ((pos_orig - (*pos)) >= 1) { *pos = pos_prev; @@ -212,21 +212,21 @@ void BLI_str_cursor_step_utf8(const char *str, } } -bool BLI_str_cursor_step_next_utf32(const char32_t *str, size_t maxlen, int *pos) +bool BLI_str_cursor_step_next_utf32(const char32_t *str, size_t str_maxlen, int *pos) { /* NOTE: Keep in sync with #BLI_str_cursor_step_next_utf8. */ - if ((*pos) >= (int)maxlen) { + if ((*pos) >= (int)str_maxlen) { return false; } do { (*pos)++; - } while (*pos < (int)maxlen && str[*pos] != 0 && BLI_wcwidth(str[*pos]) == 0); + } while (*pos < (int)str_maxlen && str[*pos] != 0 && BLI_wcwidth(str[*pos]) == 0); return true; } -bool BLI_str_cursor_step_prev_utf32(const char32_t *str, size_t UNUSED(maxlen), int *pos) +bool BLI_str_cursor_step_prev_utf32(const char32_t *str, size_t UNUSED(str_maxlen), int *pos) { /* NOTE: Keep in sync with #BLI_str_cursor_step_prev_utf8. */ @@ -241,7 +241,7 @@ bool BLI_str_cursor_step_prev_utf32(const char32_t *str, size_t UNUSED(maxlen), } void BLI_str_cursor_step_utf32(const char32_t *str, - size_t maxlen, + size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, @@ -251,21 +251,21 @@ void BLI_str_cursor_step_utf32(const char32_t *str, if (direction == STRCUR_DIR_NEXT) { if (use_init_step) { - BLI_str_cursor_step_next_utf32(str, maxlen, pos); + BLI_str_cursor_step_next_utf32(str, str_maxlen, pos); } else { BLI_assert(jump == STRCUR_JUMP_DELIM); } if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) < maxlen ? + const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? cursor_delim_type_unicode((uint)str[*pos]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type_unicode() for complete * list of special character, ctr -> */ - while ((*pos) < maxlen) { - if (BLI_str_cursor_step_next_utf32(str, maxlen, pos)) { + while ((*pos) < str_maxlen) { + if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) { if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { break; @@ -279,7 +279,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str, } else if (direction == STRCUR_DIR_PREV) { if (use_init_step) { - BLI_str_cursor_step_prev_utf32(str, maxlen, pos); + BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos); } else { BLI_assert(jump == STRCUR_JUMP_DELIM); @@ -294,7 +294,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str, * list of special character, ctr -> */ while ((*pos) > 0) { const int pos_prev = *pos; - if (BLI_str_cursor_step_prev_utf32(str, maxlen, pos)) { + if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) { if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { /* left only: compensate for index/change in direction */ diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index 9a0f0008d51..006253bf049 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -459,7 +459,8 @@ int ANIM_add_driver( int array = RNA_property_array_length(&ptr, prop); const char *dvar_prefix = (flag & CREATEDRIVER_WITH_DEFAULT_DVAR) ? "var + " : ""; char *expression = driver->expression; - int val, maxlen = sizeof(driver->expression); + const size_t expression_maxncpy = sizeof(driver->expression); + int val; float fval; if (proptype == PROP_BOOLEAN) { @@ -470,7 +471,8 @@ int ANIM_add_driver( val = RNA_property_boolean_get_index(&ptr, prop, array_index); } - BLI_snprintf(expression, maxlen, "%s%s", dvar_prefix, (val) ? "True" : "False"); + BLI_snprintf( + expression, expression_maxncpy, "%s%s", dvar_prefix, (val) ? "True" : "False"); } else if (proptype == PROP_INT) { if (!array) { @@ -480,7 +482,7 @@ int ANIM_add_driver( val = RNA_property_int_get_index(&ptr, prop, array_index); } - BLI_snprintf(expression, maxlen, "%s%d", dvar_prefix, val); + BLI_snprintf(expression, expression_maxncpy, "%s%d", dvar_prefix, val); } else if (proptype == PROP_FLOAT) { if (!array) { @@ -490,11 +492,11 @@ int ANIM_add_driver( fval = RNA_property_float_get_index(&ptr, prop, array_index); } - BLI_snprintf(expression, maxlen, "%s%.3f", dvar_prefix, fval); + BLI_snprintf(expression, expression_maxncpy, "%s%.3f", dvar_prefix, fval); BLI_str_rstrip_float_zero(expression, '\0'); } else if (flag & CREATEDRIVER_WITH_DEFAULT_DVAR) { - BLI_strncpy(expression, "var", maxlen); + BLI_strncpy(expression, "var", expression_maxncpy); } } diff --git a/source/blender/editors/asset/intern/asset_indexer.cc b/source/blender/editors/asset/intern/asset_indexer.cc index 253b099d277..bc5799f8162 100644 --- a/source/blender/editors/asset/intern/asset_indexer.cc +++ b/source/blender/editors/asset/intern/asset_indexer.cc @@ -900,10 +900,10 @@ static void update_index(const char *filename, FileIndexerEntries *entries, void asset_index_file.write_contents(content); } -static void *init_user_data(const char *root_directory, size_t root_directory_maxlen) +static void *init_user_data(const char *root_directory, size_t root_directory_maxncpy) { AssetLibraryIndex *library_index = MEM_new( - __func__, StringRef(root_directory, BLI_strnlen(root_directory, root_directory_maxlen))); + __func__, StringRef(root_directory, BLI_strnlen(root_directory, root_directory_maxncpy))); library_index->collect_preexisting_file_indices(); library_index->remove_broken_index_files(); return library_index; diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 1099c4d17a1..6c6fbc9b058 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -3175,7 +3175,7 @@ const char *UI_key_event_operator_string(const struct bContext *C, IDProperty *properties, const bool is_strict, char *result, - const int result_len); + const int result_maxncpy); /* ui_interface_region_tooltip.c */ diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc index 09ae3c2188d..54b5b048ecd 100644 --- a/source/blender/editors/interface/interface.cc +++ b/source/blender/editors/interface/interface.cc @@ -1246,7 +1246,7 @@ void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_str static bool ui_but_event_operator_string_from_operator(const bContext *C, wmOperatorCallParams *op_call_params, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { BLI_assert(op_call_params->optype != nullptr); bool found = false; @@ -1254,8 +1254,13 @@ static bool ui_but_event_operator_string_from_operator(const bContext *C, static_cast(op_call_params->opptr->data) : nullptr; - if (WM_key_event_operator_string( - C, op_call_params->optype->idname, op_call_params->opcontext, prop, true, buf, buf_len)) + if (WM_key_event_operator_string(C, + op_call_params->optype->idname, + op_call_params->opcontext, + prop, + true, + buf, + buf_maxncpy)) { found = true; } @@ -1265,7 +1270,7 @@ static bool ui_but_event_operator_string_from_operator(const bContext *C, static bool ui_but_event_operator_string_from_menu(const bContext *C, uiBut *but, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { MenuType *mt = UI_but_menutype_get(but); BLI_assert(mt != nullptr); @@ -1278,7 +1283,7 @@ static bool ui_but_event_operator_string_from_menu(const bContext *C, IDP_AddToGroup(prop_menu, IDP_NewStringMaxSize(mt->idname, "name", sizeof(mt->idname))); if (WM_key_event_operator_string( - C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true, buf, buf_len)) + C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true, buf, buf_maxncpy)) { found = true; } @@ -1290,7 +1295,7 @@ static bool ui_but_event_operator_string_from_menu(const bContext *C, static bool ui_but_event_operator_string_from_panel(const bContext *C, uiBut *but, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { /** Nearly exact copy of #ui_but_event_operator_string_from_menu */ PanelType *pt = UI_but_paneltype_get(but); @@ -1317,7 +1322,7 @@ static bool ui_but_event_operator_string_from_panel(const bContext *C, IDP_ReplaceInGroup(prop_panel, IDP_New(IDP_INT, &val, "keep_open")); if (WM_key_event_operator_string( - C, "WM_OT_call_panel", WM_OP_INVOKE_REGION_WIN, prop_panel, true, buf, buf_len)) + C, "WM_OT_call_panel", WM_OP_INVOKE_REGION_WIN, prop_panel, true, buf, buf_maxncpy)) { found = true; break; @@ -1331,7 +1336,7 @@ static bool ui_but_event_operator_string_from_panel(const bContext *C, static bool ui_but_event_operator_string(const bContext *C, uiBut *but, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { bool found = false; @@ -1340,13 +1345,13 @@ static bool ui_but_event_operator_string(const bContext *C, params.optype = but->optype; params.opptr = but->opptr; params.opcontext = but->opcontext; - found = ui_but_event_operator_string_from_operator(C, ¶ms, buf, buf_len); + found = ui_but_event_operator_string_from_operator(C, ¶ms, buf, buf_maxncpy); } else if (UI_but_menutype_get(but) != nullptr) { - found = ui_but_event_operator_string_from_menu(C, but, buf, buf_len); + found = ui_but_event_operator_string_from_menu(C, but, buf, buf_maxncpy); } else if (UI_but_paneltype_get(but) != nullptr) { - found = ui_but_event_operator_string_from_panel(C, but, buf, buf_len); + found = ui_but_event_operator_string_from_panel(C, but, buf, buf_maxncpy); } return found; @@ -1355,12 +1360,13 @@ static bool ui_but_event_operator_string(const bContext *C, static bool ui_but_extra_icon_event_operator_string(const bContext *C, uiButExtraOpIcon *extra_icon, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { wmOperatorType *extra_icon_optype = UI_but_extra_operator_icon_optype_get(extra_icon); if (extra_icon_optype) { - return ui_but_event_operator_string_from_operator(C, extra_icon->optype_params, buf, buf_len); + return ui_but_event_operator_string_from_operator( + C, extra_icon->optype_params, buf, buf_maxncpy); } return false; @@ -1369,7 +1375,7 @@ static bool ui_but_extra_icon_event_operator_string(const bContext *C, static bool ui_but_event_property_operator_string(const bContext *C, uiBut *but, char *buf, - const size_t buf_len) + const size_t buf_maxncpy) { /* Context toggle operator names to check. */ @@ -1523,7 +1529,7 @@ static bool ui_but_event_property_operator_string(const bContext *C, for (int i = 0; (i < opnames_len) && (opnames[i]); i++) { if (WM_key_event_operator_string( - C, opnames[i], WM_OP_INVOKE_REGION_WIN, prop_path, false, buf, buf_len)) + C, opnames[i], WM_OP_INVOKE_REGION_WIN, prop_path, false, buf, buf_maxncpy)) { found = true; break; @@ -2729,7 +2735,7 @@ static double ui_get_but_scale_unit(uiBut *but, double value) return BKE_scene_unit_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value); } -void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) +void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy) { if (!ui_but_is_unit(but)) { return; @@ -2741,7 +2747,8 @@ void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) orig_str = BLI_strdup(str); - BKE_unit_name_to_alt(str, maxlen, orig_str, unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type)); + BKE_unit_name_to_alt( + str, str_maxncpy, orig_str, unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type)); MEM_freeN(orig_str); } @@ -2750,7 +2757,7 @@ void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) * \param float_precision: Override the button precision. */ static void ui_get_but_string_unit( - uiBut *but, char *str, int len_max, double value, bool pad, int float_precision) + uiBut *but, char *str, int str_maxncpy, double value, bool pad, int float_precision) { UnitSettings *unit = but->block->unit; const int unit_type = UI_but_unit_type_get(but); @@ -2776,7 +2783,7 @@ static void ui_get_but_string_unit( } BKE_unit_value_as_string(str, - len_max, + str_maxncpy, ui_get_but_scale_unit(but, value), precision, RNA_SUBTYPE_UNIT_VALUE(unit_type), @@ -2822,7 +2829,7 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) void ui_but_string_get_ex(uiBut *but, char *str, - const size_t maxlen, + const size_t str_maxncpy, const int float_precision, const bool use_exp_float, bool *r_use_exp_float) @@ -2843,11 +2850,11 @@ void ui_but_string_get_ex(uiBut *but, /* uiBut.custom_data points to data this tab represents (e.g. workspace). * uiBut.rnapoin/prop store an active value (e.g. active workspace). */ RNA_pointer_create(but->rnapoin.owner_id, ptr_type, but->custom_data, &ptr); - buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len); + buf = RNA_struct_name_get_alloc(&ptr, str, str_maxncpy, &buf_len); } else if (type == PROP_STRING) { /* RNA string */ - buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len); + buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, str_maxncpy, &buf_len); } else if (type == PROP_ENUM) { /* RNA enum */ @@ -2858,14 +2865,14 @@ void ui_but_string_get_ex(uiBut *but, value, &buf)) { - BLI_strncpy(str, buf, maxlen); + BLI_strncpy(str, buf, str_maxncpy); buf = str; } } else if (type == PROP_POINTER) { /* RNA pointer */ PointerRNA ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop); - buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len); + buf = RNA_struct_name_get_alloc(&ptr, str, str_maxncpy, &buf_len); } else { BLI_assert(0); @@ -2875,23 +2882,23 @@ void ui_but_string_get_ex(uiBut *but, str[0] = '\0'; } else if (buf != str) { - BLI_assert(maxlen <= buf_len + 1); + BLI_assert(str_maxncpy <= buf_len + 1); /* string was too long, we have to truncate */ if (UI_but_is_utf8(but)) { - BLI_strncpy_utf8(str, buf, maxlen); + BLI_strncpy_utf8(str, buf, str_maxncpy); } else { - BLI_strncpy(str, buf, maxlen); + BLI_strncpy(str, buf, str_maxncpy); } MEM_freeN((void *)buf); } } else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { /* string */ - BLI_strncpy(str, but->poin, maxlen); + BLI_strncpy(str, but->poin, str_maxncpy); return; } - else if (ui_but_anim_expression_get(but, str, maxlen)) { + else if (ui_but_anim_expression_get(but, str, str_maxncpy)) { /* driver expression */ } else { @@ -2914,21 +2921,21 @@ void ui_but_string_get_ex(uiBut *but, } if (ui_but_is_unit(but)) { - ui_get_but_string_unit(but, str, maxlen, value, false, prec); + ui_get_but_string_unit(but, str, str_maxncpy, value, false, prec); } else if (subtype == PROP_FACTOR) { if (U.factor_display_type == USER_FACTOR_AS_FACTOR) { - BLI_snprintf(str, maxlen, "%.*f", prec, value); + BLI_snprintf(str, str_maxncpy, "%.*f", prec, value); } else { - BLI_snprintf(str, maxlen, "%.*f", MAX2(0, prec - 2), value * 100); + BLI_snprintf(str, str_maxncpy, "%.*f", MAX2(0, prec - 2), value * 100); } } else { const int int_digits_num = integer_digits_f(value); if (use_exp_float) { if (int_digits_num < -6 || int_digits_num > 12) { - BLI_snprintf(str, maxlen, "%.*g", prec, value); + BLI_snprintf(str, str_maxncpy, "%.*g", prec, value); if (r_use_exp_float) { *r_use_exp_float = true; } @@ -2936,24 +2943,24 @@ void ui_but_string_get_ex(uiBut *but, else { prec -= int_digits_num; CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); - BLI_snprintf(str, maxlen, "%.*f", prec, value); + BLI_snprintf(str, str_maxncpy, "%.*f", prec, value); } } else { prec -= int_digits_num; CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); - BLI_snprintf(str, maxlen, "%.*f", prec, value); + BLI_snprintf(str, str_maxncpy, "%.*f", prec, value); } } } else { - BLI_snprintf(str, maxlen, "%d", int(value)); + BLI_snprintf(str, str_maxncpy, "%d", int(value)); } } } -void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) +void ui_but_string_get(uiBut *but, char *str, const size_t str_maxncpy) { - ui_but_string_get_ex(but, str, maxlen, -1, false, nullptr); + ui_but_string_get_ex(but, str, str_maxncpy, -1, false, nullptr); } char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) diff --git a/source/blender/editors/interface/interface_anim.cc b/source/blender/editors/interface/interface_anim.cc index f8ab1f5ab7f..4d5d59f3dd8 100644 --- a/source/blender/editors/interface/interface_anim.cc +++ b/source/blender/editors/interface/interface_anim.cc @@ -171,7 +171,7 @@ void ui_but_anim_decorate_update_from_flag(uiButDecorator *but) but->flag = (but->flag & ~flag_copy) | (flag & flag_copy); } -bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen) +bool ui_but_anim_expression_get(uiBut *but, char *str, size_t str_maxncpy) { FCurve *fcu; ChannelDriver *driver; @@ -184,7 +184,7 @@ bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen) if (driver && driver->type == DRIVER_TYPE_PYTHON) { if (str) { - BLI_strncpy(str, driver->expression, maxlen); + BLI_strncpy(str, driver->expression, str_maxncpy); } return true; } diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index 818f7d5c082..9ba6b3247e7 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -399,7 +399,7 @@ struct uiHandleButtonData { /* text selection/editing */ /* size of 'str' (including terminator) */ - int maxlen; + int str_maxncpy; /* Button text selection: * extension direction, selextend, inside ui_do_but_TEX */ int sel_pos_init; @@ -3006,14 +3006,17 @@ void ui_but_active_string_clear_and_exit(bContext *C, uiBut *but) button_activate_state(C, but, BUTTON_STATE_EXIT); } -static void ui_textedit_string_ensure_max_length(uiBut *but, uiHandleButtonData *data, int maxlen) +static void ui_textedit_string_ensure_max_length(uiBut *but, + uiHandleButtonData *data, + int str_maxncpy) { BLI_assert(data->is_str_dynamic); BLI_assert(data->str == but->editstr); - if (maxlen > data->maxlen) { - data->str = but->editstr = static_cast(MEM_reallocN(data->str, sizeof(char) * maxlen)); - data->maxlen = maxlen; + if (str_maxncpy > data->str_maxncpy) { + data->str = but->editstr = static_cast( + MEM_reallocN(data->str, sizeof(char) * str_maxncpy)); + data->str_maxncpy = str_maxncpy; } } @@ -3024,10 +3027,10 @@ static void ui_textedit_string_set(uiBut *but, uiHandleButtonData *data, const c } if (UI_but_is_utf8(but)) { - BLI_strncpy_utf8(data->str, str, data->maxlen); + BLI_strncpy_utf8(data->str, str, data->str_maxncpy); } else { - BLI_strncpy(data->str, str, data->maxlen); + BLI_strncpy(data->str, str, data->str_maxncpy); } } @@ -3130,14 +3133,14 @@ static bool ui_textedit_insert_buf(uiBut *but, int buf_len) { int len = strlen(data->str); - const int len_new = len - (but->selend - but->selsta) + 1; + const int str_maxncpy_new = len - (but->selend - but->selsta) + 1; bool changed = false; if (data->is_str_dynamic) { - ui_textedit_string_ensure_max_length(but, data, len_new + buf_len); + ui_textedit_string_ensure_max_length(but, data, str_maxncpy_new + buf_len); } - if (len_new <= data->maxlen) { + if (str_maxncpy_new <= data->str_maxncpy) { char *str = data->str; size_t step = buf_len; @@ -3147,17 +3150,17 @@ static bool ui_textedit_insert_buf(uiBut *but, len = strlen(str); } - if ((len + step >= data->maxlen) && (data->maxlen - (len + 1) > 0)) { + if ((len + step >= data->str_maxncpy) && (data->str_maxncpy - (len + 1) > 0)) { if (UI_but_is_utf8(but)) { /* Shorten 'step' to a utf8 aligned size that fits. */ - BLI_strnlen_utf8_ex(buf, data->maxlen - (len + 1), &step); + BLI_strnlen_utf8_ex(buf, data->str_maxncpy - (len + 1), &step); } else { - step = data->maxlen - (len + 1); + step = data->str_maxncpy - (len + 1); } } - if (step && (len + step < data->maxlen)) { + if (step && (len + step < data->str_maxncpy)) { memmove(&str[but->pos + step], &str[but->pos], (len + 1) - but->pos); memcpy(&str[but->pos], buf, step * sizeof(char)); but->pos += step; @@ -3415,17 +3418,17 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) #endif /* retrieve string */ - data->maxlen = ui_but_string_get_max_length(but); - if (data->maxlen != 0) { - data->str = static_cast(MEM_callocN(sizeof(char) * data->maxlen, "textedit str")); + data->str_maxncpy = ui_but_string_get_max_length(but); + if (data->str_maxncpy != 0) { + data->str = static_cast(MEM_callocN(sizeof(char) * data->str_maxncpy, "textedit str")); /* We do not want to truncate precision to default here, it's nice to show value, * not to edit it - way too much precision is lost then. */ ui_but_string_get_ex( - but, data->str, data->maxlen, UI_PRECISION_FLOAT_MAX, true, &no_zero_strip); + but, data->str, data->str_maxncpy, UI_PRECISION_FLOAT_MAX, true, &no_zero_strip); } else { data->is_str_dynamic = true; - data->str = ui_but_string_get_dynamic(but, &data->maxlen); + data->str = ui_but_string_get_dynamic(but, &data->str_maxncpy); } if (ui_but_is_float(but) && !ui_but_is_unit(but) && @@ -3436,7 +3439,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) if (is_num_but) { BLI_assert(data->is_str_dynamic == false); - ui_but_convert_to_unit_alt_name(but, data->str, data->maxlen); + ui_but_convert_to_unit_alt_name(but, data->str, data->str_maxncpy); ui_numedit_begin_set_values(but, data); } diff --git a/source/blender/editors/interface/interface_intern.hh b/source/blender/editors/interface/interface_intern.hh index ae6f5c9cbce..bb644249374 100644 --- a/source/blender/editors/interface/interface_intern.hh +++ b/source/blender/editors/interface/interface_intern.hh @@ -666,11 +666,11 @@ void ui_hsvcube_pos_from_vals( */ void ui_but_string_get_ex(uiBut *but, char *str, - size_t maxlen, + size_t str_maxncpy, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); +void ui_but_string_get(uiBut *but, char *str, size_t str_maxncpy) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). @@ -681,7 +681,7 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size); /** * \param str: will be overwritten. */ -void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); +void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy) ATTR_NONNULL(); bool ui_but_string_set(bContext *C, uiBut *but, const char *str) ATTR_NONNULL(); bool ui_but_string_eval_number(bContext *C, const uiBut *but, const char *str, double *value) ATTR_NONNULL(); @@ -1280,7 +1280,7 @@ void ui_but_anim_paste_driver(bContext *C); * \a str can be NULL to only perform check if \a but has an expression at all. * \return if button has an expression. */ -bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen); +bool ui_but_anim_expression_get(uiBut *but, char *str, size_t str_maxncpy); bool ui_but_anim_expression_set(uiBut *but, const char *str); /** * Create new expression for button (i.e. a "scripted driver"), if it can be created. @@ -1348,7 +1348,7 @@ uiBut *ui_list_find_mouse_over_ex(const ARegion *region, const int xy[2]) bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT; -size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen) +size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxncpy) ATTR_NONNULL(1, 2); size_t ui_but_drawstr_len_without_sep_char(const uiBut *but); size_t ui_but_tip_len_only_first_line(const uiBut *but); diff --git a/source/blender/editors/interface/interface_ops.cc b/source/blender/editors/interface/interface_ops.cc index 8f1dcb5b330..96f450b23a2 100644 --- a/source/blender/editors/interface/interface_ops.cc +++ b/source/blender/editors/interface/interface_ops.cc @@ -1868,13 +1868,13 @@ static void UI_OT_editsource(wmOperatorType *ot) static void edittranslation_find_po_file(const char *root, const char *uilng, char *path, - const size_t maxlen) + const size_t path_maxncpy) { char tstr[32]; /* Should be more than enough! */ /* First, full lang code. */ BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng); - BLI_path_join(path, maxlen, root, uilng, tstr); + BLI_path_join(path, path_maxncpy, root, uilng, tstr); if (BLI_is_file(path)) { return; } @@ -1899,9 +1899,9 @@ static void edittranslation_find_po_file(const char *root, BLI_strncpy(tstr + szt, tc, sizeof(tstr) - szt); } - BLI_path_join(path, maxlen, root, tstr); + BLI_path_join(path, path_maxncpy, root, tstr); BLI_strncat(tstr, ".po", sizeof(tstr)); - BLI_path_append(path, maxlen, tstr); + BLI_path_append(path, path_maxncpy, tstr); if (BLI_is_file(path)) { return; } diff --git a/source/blender/editors/interface/interface_query.cc b/source/blender/editors/interface/interface_query.cc index 502b0bb4e3f..133aa57e1a0 100644 --- a/source/blender/editors/interface/interface_query.cc +++ b/source/blender/editors/interface/interface_query.cc @@ -583,10 +583,10 @@ size_t ui_but_drawstr_len_without_sep_char(const uiBut *but) return strlen(but->drawstr); } -size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen) +size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxncpy) { size_t str_len_clip = ui_but_drawstr_len_without_sep_char(but); - return BLI_strncpy_rlen(str, but->drawstr, min_zz(str_len_clip + 1, str_maxlen)); + return BLI_strncpy_rlen(str, but->drawstr, min_zz(str_len_clip + 1, str_maxncpy)); } size_t ui_but_tip_len_only_first_line(const uiBut *but) diff --git a/source/blender/editors/interface/interface_utils.cc b/source/blender/editors/interface/interface_utils.cc index bbb726811d3..227f1642914 100644 --- a/source/blender/editors/interface/interface_utils.cc +++ b/source/blender/editors/interface/interface_utils.cc @@ -1134,7 +1134,7 @@ const char *UI_key_event_operator_string(const bContext *C, IDProperty *properties, const bool is_strict, char *result, - const int result_len) + const int result_maxncpy) { /* NOTE: currently only actions on UI Lists are supported (for the asset manager). * Other kinds of events can be supported as needed. */ @@ -1196,7 +1196,7 @@ const char *UI_key_event_operator_string(const bContext *C, if ((event_val != KM_NOTHING) && (event_type != KM_NOTHING)) { WM_keymap_item_raw_to_string( - false, false, false, false, 0, event_val, event_type, false, result, result_len); + false, false, false, false, 0, event_val, event_type, false, result, result_maxncpy); return result; } diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index c1c21bebf2b..1cc89fe2795 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -90,7 +90,7 @@ static void textview_draw_sel(const char *str, * \return The length in bytes. */ static int textview_wrap_offsets( - const char *str, int len, int width, int *r_lines, int **r_offsets) + const char *str, const int str_len, const int width, int *r_lines, int **r_offsets) { int i, end; /* Offset as unicode code-point. */ int j; /* Offset as bytes. */ @@ -99,11 +99,11 @@ static int textview_wrap_offsets( *r_offsets = MEM_callocN( sizeof(**r_offsets) * - (len * BLI_UTF8_WIDTH_MAX / MAX2(1, width - (BLI_UTF8_WIDTH_MAX - 1)) + 1), + (str_len * BLI_UTF8_WIDTH_MAX / MAX2(1, width - (BLI_UTF8_WIDTH_MAX - 1)) + 1), __func__); (*r_offsets)[0] = 0; - for (i = 0, end = width, j = 0; j < len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { + for (i = 0, end = width, j = 0; j < str_len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { int columns = BLI_str_utf8_char_width_safe(str + j); if (i + columns > end) { diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index d40ad77bcf3..f4f5ee8e94c 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -1322,13 +1322,13 @@ void NODE_OT_select_same_type_step(wmOperatorType *ot) /** \name Find Node by Name Operator * \{ */ -static void node_find_create_label(const bNode *node, char *str, int maxlen) +static void node_find_create_label(const bNode *node, char *str, int str_maxncpy) { if (node->label[0]) { - BLI_snprintf(str, maxlen, "%s (%s)", node->name, node->label); + BLI_snprintf(str, str_maxncpy, "%s (%s)", node->name, node->label); } else { - BLI_strncpy(str, node->name, maxlen); + BLI_strncpy(str, node->name, str_maxncpy); } } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index b9c9bd6423f..0cadb1b3a39 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -801,7 +801,7 @@ static const char *draw_seq_text_get_name(Sequence *seq) return name; } -static void draw_seq_text_get_source(Sequence *seq, char *r_source, size_t source_len) +static void draw_seq_text_get_source(Sequence *seq, char *r_source, size_t source_maxncpy) { *r_source = '\0'; @@ -809,48 +809,48 @@ static void draw_seq_text_get_source(Sequence *seq, char *r_source, size_t sourc switch (seq->type) { case SEQ_TYPE_IMAGE: case SEQ_TYPE_MOVIE: { - BLI_path_join(r_source, source_len, seq->strip->dir, seq->strip->stripdata->name); + BLI_path_join(r_source, source_maxncpy, seq->strip->dir, seq->strip->stripdata->name); break; } case SEQ_TYPE_SOUND_RAM: { if (seq->sound != NULL) { - BLI_strncpy(r_source, seq->sound->filepath, source_len); + BLI_strncpy(r_source, seq->sound->filepath, source_maxncpy); } break; } case SEQ_TYPE_MULTICAM: { - BLI_snprintf(r_source, source_len, "Channel: %d", seq->multicam_source); + BLI_snprintf(r_source, source_maxncpy, "Channel: %d", seq->multicam_source); break; } case SEQ_TYPE_TEXT: { const TextVars *textdata = seq->effectdata; - BLI_strncpy(r_source, textdata->text, source_len); + BLI_strncpy(r_source, textdata->text, source_maxncpy); break; } case SEQ_TYPE_SCENE: { if (seq->scene != NULL) { if (seq->scene_camera != NULL) { BLI_snprintf(r_source, - source_len, + source_maxncpy, "%s (%s)", seq->scene->id.name + 2, seq->scene_camera->id.name + 2); } else { - BLI_strncpy(r_source, seq->scene->id.name + 2, source_len); + BLI_strncpy(r_source, seq->scene->id.name + 2, source_maxncpy); } } break; } case SEQ_TYPE_MOVIECLIP: { if (seq->clip != NULL) { - BLI_strncpy(r_source, seq->clip->id.name + 2, source_len); + BLI_strncpy(r_source, seq->clip->id.name + 2, source_maxncpy); } break; } case SEQ_TYPE_MASK: { if (seq->mask != NULL) { - BLI_strncpy(r_source, seq->mask->id.name + 2, source_len); + BLI_strncpy(r_source, seq->mask->id.name + 2, source_maxncpy); } break; } diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index 89c35165834..8821d3e09c0 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -174,17 +174,17 @@ static void transdata_elem_translate_fn(void *__restrict iter_data_v, * \{ */ static void translate_dist_to_str(char *r_str, - const int len_max, + const int r_str_maxncpy, const float val, const UnitSettings *unit) { if (unit) { BKE_unit_value_as_string( - r_str, len_max, val * unit->scale_length, 4, B_UNIT_LENGTH, unit, false); + r_str, r_str_maxncpy, val * unit->scale_length, 4, B_UNIT_LENGTH, unit, false); } else { /* Check range to prevent string buffer overflow. */ - BLI_snprintf(r_str, len_max, IN_RANGE_INCL(val, -1e10f, 1e10f) ? "%.4f" : "%.4e", val); + BLI_snprintf(r_str, r_str_maxncpy, IN_RANGE_INCL(val, -1e10f, 1e10f) ? "%.4f" : "%.4e", val); } } diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index c3fe07e9496..01d390900c4 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -308,15 +308,15 @@ void rna_object_vgroup_name_index_set(struct PointerRNA *ptr, const char *value, void rna_object_vgroup_name_set(struct PointerRNA *ptr, const char *value, char *result, - int maxlen); + int result_maxncpy); void rna_object_uvlayer_name_set(struct PointerRNA *ptr, const char *value, char *result, - int maxlen); + int result_maxncpy); void rna_object_vcollayer_name_set(struct PointerRNA *ptr, const char *value, char *result, - int maxlen); + int result_maxncpy); PointerRNA rna_object_shapekey_index_get(struct ID *id, int value); int rna_object_shapekey_index_set(struct ID *id, PointerRNA value, int current); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 9de260c198a..87b0a28df2a 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1863,7 +1863,10 @@ static void rna_Node_draw_buttons_ext(struct uiLayout *layout, bContext *C, Poin RNA_parameter_list_free(&list); } -static void rna_Node_draw_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen) +static void rna_Node_draw_label(const bNodeTree *ntree, + const bNode *node, + char *label, + int label_maxncpy) { extern FunctionRNA rna_Node_draw_label_func; @@ -1881,7 +1884,7 @@ static void rna_Node_draw_label(const bNodeTree *ntree, const bNode *node, char RNA_parameter_get_lookup(&list, "label", &ret); rlabel = (char *)ret; - BLI_strncpy(label, rlabel != NULL ? rlabel : "", maxlen); + BLI_strncpy(label, rlabel != NULL ? rlabel : "", label_maxncpy); RNA_parameter_list_free(&list); } diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index c478049b447..0b4397905a3 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -939,7 +939,10 @@ void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index = BKE_object_defgroup_name_index(ob, value) + 1; } -void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +void rna_object_vgroup_name_set(PointerRNA *ptr, + const char *value, + char *result, + int result_maxncpy) { Object *ob = (Object *)ptr->owner_id; if (!BKE_object_supports_vertex_groups(ob)) { @@ -950,7 +953,7 @@ void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result bDeformGroup *dg = BKE_object_defgroup_find_name(ob, value); if (dg) { /* No need for BLI_strncpy_utf8, since this matches an existing group. */ - BLI_strncpy(result, value, maxlen); + BLI_strncpy(result, value, result_maxncpy); return; } @@ -1029,20 +1032,23 @@ void rna_object_BKE_object_facemap_name_index_set(PointerRNA *ptr, const char *v *index = BKE_object_facemap_name_index(ob, value) + 1; } -void rna_object_fmap_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +void rna_object_fmap_name_set(PointerRNA *ptr, const char *value, char *result, int result_maxncpy) { Object *ob = (Object *)ptr->owner_id; bFaceMap *fmap = BKE_object_facemap_find_name(ob, value); if (fmap) { /* No need for BLI_strncpy_utf8, since this matches an existing group. */ - BLI_strncpy(result, value, maxlen); + BLI_strncpy(result, value, result_maxncpy); return; } result[0] = '\0'; } -void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +void rna_object_uvlayer_name_set(PointerRNA *ptr, + const char *value, + char *result, + int result_maxncpy) { Object *ob = (Object *)ptr->owner_id; Mesh *me; @@ -1056,7 +1062,7 @@ void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *resul layer = &me->ldata.layers[a]; if (layer->type == CD_PROP_FLOAT2 && STREQ(layer->name, value)) { - BLI_strncpy(result, value, maxlen); + BLI_strncpy(result, value, result_maxncpy); return; } } @@ -1065,7 +1071,10 @@ void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *resul result[0] = '\0'; } -void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +void rna_object_vcollayer_name_set(PointerRNA *ptr, + const char *value, + char *result, + int result_maxncpy) { Object *ob = (Object *)ptr->owner_id; Mesh *me; @@ -1079,7 +1088,7 @@ void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *res layer = &me->fdata.layers[a]; if (layer->type == CD_MCOL && STREQ(layer->name, value)) { - BLI_strncpy(result, value, maxlen); + BLI_strncpy(result, value, result_maxncpy); return; } } diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 6ddd06608d5..79b47aefb0e 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -537,14 +537,17 @@ static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, s *index = 0; } -static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +static void rna_pose_pgroup_name_set(PointerRNA *ptr, + const char *value, + char *result, + int result_maxncpy) { bPose *pose = (bPose *)ptr->data; bActionGroup *grp; for (grp = pose->agroups.first; grp; grp = grp->next) { if (STREQ(grp->name, value)) { - BLI_strncpy(result, value, maxlen); + BLI_strncpy(result, value, result_maxncpy); return; } } diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.cc b/source/blender/nodes/composite/nodes/node_composite_mask.cc index 840fcafb63f..fca6a6d3a5a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mask.cc +++ b/source/blender/nodes/composite/nodes/node_composite_mask.cc @@ -42,13 +42,13 @@ static void node_composit_init_mask(bNodeTree * /*ntree*/, bNode *node) static void node_mask_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, - int maxlen) + int label_maxncpy) { if (node->id != nullptr) { - BLI_strncpy(label, node->id->name + 2, maxlen); + BLI_strncpy(label, node->id->name + 2, label_maxncpy); } else { - BLI_strncpy(label, IFACE_("Mask"), maxlen); + BLI_strncpy(label, IFACE_("Mask"), label_maxncpy); } } diff --git a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc index 310c388f8ad..93cf6b14e09 100644 --- a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc +++ b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc @@ -28,13 +28,13 @@ static void cmp_node_moviedistortion_declare(NodeDeclarationBuilder &b) b.add_output(N_("Image")); } -static void label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +static void label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int label_maxncpy) { if (node->custom1 == 0) { - BLI_strncpy(label, IFACE_("Undistortion"), maxlen); + BLI_strncpy(label, IFACE_("Undistortion"), label_maxncpy); } else { - BLI_strncpy(label, IFACE_("Distortion"), maxlen); + BLI_strncpy(label, IFACE_("Distortion"), label_maxncpy); } } diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc index 5e99d3e1cdb..31133339799 100644 --- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc @@ -34,14 +34,17 @@ static void node_update(bNodeTree *ntree, bNode *node) nodeSetSocketAvailability(ntree, sockB, !ELEM(node->custom1, NODE_BOOLEAN_MATH_NOT)); } -static void node_label(const bNodeTree * /*tree*/, const bNode *node, char *label, int maxlen) +static void node_label(const bNodeTree * /*tree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_boolean_math_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index fe18e39941c..01d3118a08e 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -173,7 +173,10 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -static void node_label(const bNodeTree * /*tree*/, const bNode *node, char *label, int maxlen) +static void node_label(const bNodeTree * /*tree*/, + const bNode *node, + char *label, + int label_maxncpy) { const NodeFunctionCompare *data = (NodeFunctionCompare *)node->storage; const char *name; @@ -181,7 +184,7 @@ static void node_label(const bNodeTree * /*tree*/, const bNode *node, char *labe if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } static float component_average(float3 a) diff --git a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc index ea149eddfc1..b1508135297 100644 --- a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc +++ b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc @@ -26,14 +26,17 @@ static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) uiItemR(layout, ptr, "rounding_mode", 0, "", ICON_NONE); } -static void node_label(const bNodeTree * /*tree*/, const bNode *node, char *label, int maxlen) +static void node_label(const bNodeTree * /*tree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_float_to_int_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } static const mf::MultiFunction *get_multi_function(const bNode &bnode) diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index 9a6088803b8..78e2dd47022 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -70,9 +70,13 @@ bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identif return find_matching_socket(groupnode->outputs, identifier); } -void node_group_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +void node_group_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { - BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen); + BLI_strncpy( + label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), label_maxncpy); } bool node_group_poll_instance(const bNode *node, diff --git a/source/blender/nodes/intern/node_common.h b/source/blender/nodes/intern/node_common.h index 9674ac4b5fb..6caf11185a6 100644 --- a/source/blender/nodes/intern/node_common.h +++ b/source/blender/nodes/intern/node_common.h @@ -19,7 +19,7 @@ struct bNodeTree; void node_group_label(const struct bNodeTree *ntree, const struct bNode *node, char *label, - int maxlen); + int label_maxncpy); bool node_group_poll_instance(const struct bNode *node, const struct bNodeTree *nodetree, const char **r_disabled_hint); diff --git a/source/blender/nodes/intern/node_util.cc b/source/blender/nodes/intern/node_util.cc index 3ac03dad68e..c6196d481a4 100644 --- a/source/blender/nodes/intern/node_util.cc +++ b/source/blender/nodes/intern/node_util.cc @@ -175,54 +175,66 @@ void node_math_update(bNodeTree *ntree, bNode *node) /** \name Labels * \{ */ -void node_blend_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +void node_blend_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } -void node_image_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +void node_image_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { /* If there is no loaded image, return an empty string, * and let nodeLabel() fill in the proper type translation. */ - BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", maxlen); + BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", label_maxncpy); } -void node_math_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +void node_math_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_math_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), maxlen); + BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), label_maxncpy); } void node_vector_math_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, - int maxlen) + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } -void node_filter_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +void node_filter_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name); if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode) diff --git a/source/blender/nodes/intern/node_util.hh b/source/blender/nodes/intern/node_util.hh index 676e1d780fc..735668187b7 100644 --- a/source/blender/nodes/intern/node_util.hh +++ b/source/blender/nodes/intern/node_util.hh @@ -35,11 +35,14 @@ void node_sock_label_clear(bNodeSocket *sock); void node_math_update(bNodeTree *ntree, bNode *node); /**** Labels ****/ -void node_blend_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen); -void node_image_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen); -void node_math_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen); -void node_vector_math_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen); -void node_filter_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen); +void node_blend_label(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy); +void node_image_label(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy); +void node_math_label(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy); +void node_vector_math_label(const bNodeTree *ntree, + const bNode *node, + char *label, + int label_maxncpy); +void node_filter_label(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy); void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode); /*** Link Handling */ diff --git a/source/blender/nodes/shader/nodes/node_shader_mix.cc b/source/blender/nodes/shader/nodes/node_shader_mix.cc index 65d209caaac..d0251747ee9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mix.cc +++ b/source/blender/nodes/shader/nodes/node_shader_mix.cc @@ -77,7 +77,7 @@ static void sh_node_mix_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *p static void sh_node_mix_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, - int maxlen) + int label_maxncpy) { const NodeShaderMix &storage = node_storage(*node); if (storage.data_type == SOCK_RGBA) { @@ -86,7 +86,7 @@ static void sh_node_mix_label(const bNodeTree * /*ntree*/, if (!enum_label) { name = "Unknown"; } - BLI_strncpy(label, IFACE_(name), maxlen); + BLI_strncpy(label, IFACE_(name), label_maxncpy); } } diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index f4bb31c7522..3bc1b286587 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -571,12 +571,12 @@ void PyC_ObSpit(const char *name, PyObject *var) } } -void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var) +void PyC_ObSpitStr(char *result, size_t result_maxncpy, PyObject *var) { /* No name, creator of string can manage that. */ const char *null_str = ""; if (var == NULL) { - BLI_snprintf(result, result_len, "%s", null_str); + BLI_snprintf(result, result_maxncpy, "%s", null_str); } else { const PyTypeObject *type = Py_TYPE(var); @@ -587,7 +587,7 @@ void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var) PyErr_Clear(); } BLI_snprintf(result, - result_len, + result_maxncpy, " ref=%d, ptr=%p, type=%s, value=%.200s", (int)var->ob_refcnt, (void *)var, diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index b0e6c9579fb..a6fbd4b4423 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -21,7 +21,7 @@ void PyC_ObSpit(const char *name, PyObject *var); * A version of #PyC_ObSpit that writes into a string (and doesn't take a name argument). * Use for logging. */ -void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var); +void PyC_ObSpitStr(char *result, size_t result_maxncpy, PyObject *var); void PyC_LineSpit(void); void PyC_StackSpit(void); PyObject *PyC_ExceptionBuffer(void); diff --git a/source/blender/python/intern/bpy_interface_run.c b/source/blender/python/intern/bpy_interface_run.c index 2d50980d6f0..42d1f718a92 100644 --- a/source/blender/python/intern/bpy_interface_run.c +++ b/source/blender/python/intern/bpy_interface_run.c @@ -52,12 +52,12 @@ static void python_script_error_jump_text(Text *text, const char *filepath) * Generate a `filepath` from a text-block so we can tell what file a text block comes from. */ static void bpy_text_filepath_get(char *filepath, - const size_t filepath_maxlen, + const size_t filepath_maxncpy, const Main *bmain, const Text *text) { BLI_snprintf(filepath, - filepath_maxlen, + filepath_maxncpy, "%s%c%s", ID_BLEND_PATH(bmain, &text->id), SEP, diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 539d7d6dc59..64109aaa39b 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -62,7 +62,10 @@ wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, wmKeyMapItem *WM_keymap_add_item_copy(struct wmKeyMap *keymap, wmKeyMapItem *kmi_src); bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); -int WM_keymap_item_to_string(const wmKeyMapItem *kmi, bool compact, char *result, int result_len); +int WM_keymap_item_to_string(const wmKeyMapItem *kmi, + bool compact, + char *result, + int result_maxncpy); wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid); wmKeyMap *WM_keymap_list_find_spaceid_or_empty(ListBase *lb, @@ -133,13 +136,13 @@ void WM_keymap_fix_linking(void); /* Modal Keymap */ int WM_modalkeymap_items_to_string( - const struct wmKeyMap *km, int propvalue, bool compact, char *result, int result_len); + const struct wmKeyMap *km, int propvalue, bool compact, char *result, int result_maxncpy); int WM_modalkeymap_operator_items_to_string( - struct wmOperatorType *ot, int propvalue, bool compact, char *result, int result_len); + struct wmOperatorType *ot, int propvalue, bool compact, char *result, int result_maxncpy); char *WM_modalkeymap_operator_items_to_string_buf(struct wmOperatorType *ot, int propvalue, bool compact, - int max_len, + int result_maxncpy, int *r_available_len, char **r_result); @@ -180,7 +183,7 @@ int WM_keymap_item_raw_to_string(short shift, short type, bool compact, char *result, - int result_len); + int result_maxncpy); /** * \param include_mask, exclude_mask: * Event types to include/exclude when looking up keys (#eEventType_Mask). @@ -198,7 +201,7 @@ char *WM_key_event_operator_string(const struct bContext *C, struct IDProperty *properties, bool is_strict, char *result, - int result_len); + int result_maxncpy); wmKeyMapItem *WM_key_event_operator_from_keymap(struct wmKeyMap *keymap, const char *opname, diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index 1ae7e157c1a..c936b772d73 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -44,22 +44,22 @@ struct FlagIdentifierPair { }; static void event_ids_from_flag(char *str, - const int str_maxlen, + const int str_maxncpy, const struct FlagIdentifierPair *flag_data, const int flag_data_len, const uint flag) { int ofs = 0; - ofs += BLI_strncpy_rlen(str + ofs, "{", str_maxlen - ofs); + ofs += BLI_strncpy_rlen(str + ofs, "{", str_maxncpy - ofs); for (int i = 0; i < flag_data_len; i++) { if (flag & flag_data[i].flag) { if (ofs != 1) { - ofs += BLI_strncpy_rlen(str + ofs, "|", str_maxlen - ofs); + ofs += BLI_strncpy_rlen(str + ofs, "|", str_maxncpy - ofs); } - ofs += BLI_strncpy_rlen(str + ofs, flag_data[i].id, str_maxlen - ofs); + ofs += BLI_strncpy_rlen(str + ofs, flag_data[i].id, str_maxncpy - ofs); } } - ofs += BLI_strncpy_rlen(str + ofs, "}", str_maxlen - ofs); + ofs += BLI_strncpy_rlen(str + ofs, "}", str_maxncpy - ofs); } static void event_ids_from_type_and_value(const short type, diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 6bf4e127fee..90869667e2b 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -2894,19 +2894,19 @@ static const char *keymap_handler_log_action_str(const eHandlerActionFlag action static const char *keymap_handler_log_kmi_event_str(const wmKeyMapItem *kmi, char *buf, - size_t buf_maxlen) + size_t buf_maxncpy) { /* Short representation of the key that was pressed, * include this since it may differ from the event in minor details * which can help looking up the key-map definition. */ - WM_keymap_item_to_string(kmi, false, buf, buf_maxlen); + WM_keymap_item_to_string(kmi, false, buf, buf_maxncpy); return buf; } static const char *keymap_handler_log_kmi_op_str(bContext *C, const wmKeyMapItem *kmi, char *buf, - size_t buf_maxlen) + size_t buf_maxncpy) { /* The key-map item properties can further help distinguish this item from others. */ char *kmi_props = nullptr; @@ -2919,7 +2919,7 @@ static const char *keymap_handler_log_kmi_op_str(bContext *C, kmi_props = IDP_reprN(kmi->properties, nullptr); } } - BLI_snprintf(buf, buf_maxlen, "%s(%s)", kmi->idname, kmi_props ? kmi_props : ""); + BLI_snprintf(buf, buf_maxncpy, "%s(%s)", kmi->idname, kmi_props ? kmi_props : ""); if (kmi_props != nullptr) { MEM_freeN(kmi_props); } diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 936eab3b21b..46045361243 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -1151,7 +1151,7 @@ int WM_keymap_item_raw_to_string(const short shift, const short type, const bool compact, char *result, - const int result_len) + const int result_maxncpy) { /* TODO: also support (some) value, like e.g. double-click? */ @@ -1212,7 +1212,7 @@ int WM_keymap_item_raw_to_string(const short shift, BLI_assert(p - buf < sizeof(buf)); /* We need utf8 here, otherwise we may 'cut' some unicode chars like arrows... */ - return BLI_strncpy_utf8_rlen(result, buf, result_len); + return BLI_strncpy_utf8_rlen(result, buf, result_maxncpy); #undef ADD_SEP } @@ -1220,7 +1220,7 @@ int WM_keymap_item_raw_to_string(const short shift, int WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact, char *result, - const int result_len) + const int result_maxncpy) { return WM_keymap_item_raw_to_string(kmi->shift, kmi->ctrl, @@ -1231,16 +1231,16 @@ int WM_keymap_item_to_string(const wmKeyMapItem *kmi, kmi->type, compact, result, - result_len); + result_maxncpy); } int WM_modalkeymap_items_to_string(const wmKeyMap *km, const int propvalue, const bool compact, char *result, - const int result_len) + const int result_maxncpy) { - BLI_assert(result_len > 0); + BLI_assert(result_maxncpy > 0); const wmKeyMapItem *kmi; if (km == NULL || (kmi = WM_modalkeymap_find_propvalue(km, propvalue)) == NULL) { @@ -1250,10 +1250,10 @@ int WM_modalkeymap_items_to_string(const wmKeyMap *km, int totlen = 0; do { - totlen += WM_keymap_item_to_string(kmi, compact, &result[totlen], result_len - totlen); + totlen += WM_keymap_item_to_string(kmi, compact, &result[totlen], result_maxncpy - totlen); if ((kmi = wm_modalkeymap_find_propvalue_iter(km, kmi, propvalue)) == NULL || - totlen >= (result_len - 2)) + totlen >= (result_maxncpy - 2)) { break; } @@ -1269,17 +1269,17 @@ int WM_modalkeymap_operator_items_to_string(wmOperatorType *ot, const int propvalue, const bool compact, char *result, - const int result_len) + const int result_maxncpy) { wmWindowManager *wm = G_MAIN->wm.first; wmKeyMap *keymap = WM_keymap_active(wm, ot->modalkeymap); - return WM_modalkeymap_items_to_string(keymap, propvalue, compact, result, result_len); + return WM_modalkeymap_items_to_string(keymap, propvalue, compact, result, result_maxncpy); } char *WM_modalkeymap_operator_items_to_string_buf(wmOperatorType *ot, const int propvalue, const bool compact, - const int max_len, + const int result_maxncpy, int *r_available_len, char **r_result) { @@ -1287,7 +1287,7 @@ char *WM_modalkeymap_operator_items_to_string_buf(wmOperatorType *ot, if (*r_available_len > 1) { int used_len = WM_modalkeymap_operator_items_to_string( - ot, propvalue, compact, ret, min_ii(*r_available_len, max_len)) + + ot, propvalue, compact, ret, min_ii(*r_available_len, result_maxncpy)) + 1; *r_available_len -= used_len; @@ -1648,7 +1648,7 @@ char *WM_key_event_operator_string(const bContext *C, IDProperty *properties, const bool is_strict, char *result, - const int result_len) + const int result_maxncpy) { wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, @@ -1661,12 +1661,12 @@ char *WM_key_event_operator_string(const bContext *C, }, NULL); if (kmi) { - WM_keymap_item_to_string(kmi, false, result, result_len); + WM_keymap_item_to_string(kmi, false, result, result_maxncpy); return result; } /* Check UI state (non key-map actions for UI regions). */ - if (UI_key_event_operator_string(C, opname, properties, is_strict, result, result_len)) { + if (UI_key_event_operator_string(C, opname, properties, is_strict, result, result_maxncpy)) { return result; }