diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index a938e3ccd93..d9e123edf7a 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -4173,21 +4173,21 @@ void GreasePencil::rename_node(Main &bmain, /* Update the layer name of the influence data of the modifiers. */ LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { char *dst_layer_name = nullptr; - size_t dst_layer_name_len = 0; + size_t dst_layer_name_maxncpy = 0; /* LineArt doesn't use the `GreasePencilModifierInfluenceData` struct. */ if (md->type == eModifierType_GreasePencilLineart) { auto *lmd = reinterpret_cast(md); dst_layer_name = lmd->target_layer; - dst_layer_name_len = sizeof(lmd->target_layer); + dst_layer_name_maxncpy = sizeof(lmd->target_layer); } else if (GreasePencilModifierInfluenceData *influence_data = influence_data_from_modifier( md)) { dst_layer_name = influence_data->layer_name; - dst_layer_name_len = sizeof(influence_data->layer_name); + dst_layer_name_maxncpy = sizeof(influence_data->layer_name); } if (dst_layer_name && STREQ(dst_layer_name, old_name.c_str())) { - BLI_strncpy(dst_layer_name, node.name().c_str(), dst_layer_name_len); + BLI_strncpy(dst_layer_name, node.name().c_str(), dst_layer_name_maxncpy); } } } diff --git a/source/blender/blenkernel/intern/workspace.cc b/source/blender/blenkernel/intern/workspace.cc index 766c515faf4..1e8736c094e 100644 --- a/source/blender/blenkernel/intern/workspace.cc +++ b/source/blender/blenkernel/intern/workspace.cc @@ -514,7 +514,7 @@ void BKE_workspace_tool_id_replace_table(WorkSpace *workspace, int replace_table_num) { const size_t idname_prefix_len = idname_prefix_skip ? strlen(idname_prefix_skip) : 0; - const size_t idname_suffix_len = sizeof(bToolRef::idname) - idname_prefix_len; + const size_t idname_suffix_maxncpy = sizeof(bToolRef::idname) - idname_prefix_len; LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { if (!(tref->space_type == space_type && tref->mode == mode)) { @@ -528,7 +528,7 @@ void BKE_workspace_tool_id_replace_table(WorkSpace *workspace, idname_suffix += idname_prefix_len; } BLI_string_replace_table_exact( - idname_suffix, idname_suffix_len, replace_table, replace_table_num); + idname_suffix, idname_suffix_maxncpy, replace_table, replace_table_num); } } diff --git a/source/blender/blenlib/BLI_string_utils.hh b/source/blender/blenlib/BLI_string_utils.hh index 2cb4115a9b7..5c00de14ac2 100644 --- a/source/blender/blenlib/BLI_string_utils.hh +++ b/source/blender/blenlib/BLI_string_utils.hh @@ -64,7 +64,7 @@ void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1); * \note Larger tables should use a hash table. */ bool BLI_string_replace_table_exact(char *string, - size_t string_len, + size_t string_maxncpy, const char *replace_table[][2], int replace_table_len); diff --git a/source/blender/blenlib/BLI_system.h b/source/blender/blenlib/BLI_system.h index dd9b4175ed5..5f06b6e5012 100644 --- a/source/blender/blenlib/BLI_system.h +++ b/source/blender/blenlib/BLI_system.h @@ -29,9 +29,9 @@ char *BLI_cpu_brand_string(void); * purposes, and not for reachability over a network. * * \param buffer: Character buffer to write the hostname into. - * \param bufsize: Size of the character buffer, including trailing '\0'. + * \param buffer_maxncpy: Size of the character buffer, including trailing '\0'. */ -void BLI_hostname_get(char *buffer, size_t bufsize); +void BLI_hostname_get(char *buffer, size_t buffer_maxncpy); /** Get maximum addressable memory in megabytes. */ size_t BLI_system_memory_max_in_megabytes(void); diff --git a/source/blender/blenlib/intern/string_utils.cc b/source/blender/blenlib/intern/string_utils.cc index 0e3af9d2bfb..d057a573fa4 100644 --- a/source/blender/blenlib/intern/string_utils.cc +++ b/source/blender/blenlib/intern/string_utils.cc @@ -111,15 +111,15 @@ void BLI_string_replace_char(char *str, char src, char dst) } bool BLI_string_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; } } diff --git a/source/blender/blenlib/intern/system.cc b/source/blender/blenlib/intern/system.cc index da0700cf0b5..fd44b33b26a 100644 --- a/source/blender/blenlib/intern/system.cc +++ b/source/blender/blenlib/intern/system.cc @@ -180,18 +180,18 @@ int BLI_cpu_support_sse42() return 0; } -void BLI_hostname_get(char *buffer, size_t bufsize) +void BLI_hostname_get(char *buffer, size_t buffer_maxncpy) { #ifndef WIN32 - if (gethostname(buffer, bufsize - 1) < 0) { - BLI_strncpy(buffer, "-unknown-", bufsize); + if (gethostname(buffer, buffer_maxncpy - 1) < 0) { + BLI_strncpy(buffer, "-unknown-", buffer_maxncpy); } /* When `gethostname()` truncates, it doesn't guarantee the trailing `\0`. */ - buffer[bufsize - 1] = '\0'; + buffer[buffer_maxncpy - 1] = '\0'; #else - DWORD bufsize_inout = bufsize; - if (!GetComputerName(buffer, &bufsize_inout)) { - BLI_strncpy(buffer, "-unknown-", bufsize); + DWORD buffer_size_in_out = buffer_maxncpy; + if (!GetComputerName(buffer, &buffer_size_in_out)) { + BLI_strncpy(buffer, "-unknown-", buffer_maxncpy); } #endif } diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index 43ef4b82b23..9c5434cd595 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -1676,7 +1676,7 @@ blender::Vector UI_text_clip_multiline_middle( const uiFontStyle *fstyle, const char *str, char *clipped_str_buf, - const size_t max_len_clipped_str_buf, + const size_t clipped_str_buf_maxncpy, const float max_line_width, const int max_lines) { @@ -1697,21 +1697,21 @@ blender::Vector UI_text_clip_multiline_middle( clipped_lines.reserve(max_lines); if (max_lines == 1) { - BLI_strncpy(clipped_str_buf, str, max_len_clipped_str_buf); + BLI_strncpy(clipped_str_buf, str, clipped_str_buf_maxncpy); UI_text_clip_middle_ex( - fstyle, clipped_str_buf, max_line_width, UI_ICON_SIZE, max_len_clipped_str_buf, '\0'); + fstyle, clipped_str_buf, max_line_width, UI_ICON_SIZE, clipped_str_buf_maxncpy, '\0'); clipped_lines.append(clipped_str_buf); return clipped_lines; } if (max_lines == 2) { clipped_lines.append(lines[0]); - BLI_strncpy(clipped_str_buf, str + lines[0].size(), max_len_clipped_str_buf); + BLI_strncpy(clipped_str_buf, str + lines[0].size(), clipped_str_buf_maxncpy); UI_text_clip_middle_ex(fstyle, clipped_str_buf, max_line_width, UI_ICON_SIZE, - max_len_clipped_str_buf, + clipped_str_buf_maxncpy, '\0', false); clipped_lines.append(clipped_str_buf); @@ -1729,12 +1729,12 @@ blender::Vector UI_text_clip_multiline_middle( /* Clip the middle of the middle line. */ { - BLI_strncpy(clipped_str_buf, lines[middle_index].data(), max_len_clipped_str_buf); + BLI_strncpy(clipped_str_buf, lines[middle_index].data(), clipped_str_buf_maxncpy); UI_text_clip_middle_ex(fstyle, clipped_str_buf, max_line_width, UI_ICON_SIZE, - max_len_clipped_str_buf, + clipped_str_buf_maxncpy, '\0', false); clipped_lines.append(clipped_str_buf); diff --git a/source/blender/nodes/function/nodes/node_fn_bit_math.cc b/source/blender/nodes/function/nodes/node_fn_bit_math.cc index 2f1ae025bf7..709041532c0 100644 --- a/source/blender/nodes/function/nodes/node_fn_bit_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_bit_math.cc @@ -118,7 +118,10 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -static void node_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +static void node_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { char name[64] = {0}; const char *operation_name = IFACE_("Unknown"); @@ -127,7 +130,7 @@ static void node_label(const bNodeTree * /*ntree*/, const bNode *node, char *lab RNA_enum_name_gettexted( bit_math_operation_items.data(), node->custom1, BLT_I18NCONTEXT_DEFAULT, &operation_name); SNPRINTF(name, IFACE_("Bitwise %s"), operation_name); - BLI_strncpy(label, name, maxlen); + BLI_strncpy(label, name, label_maxncpy); } static const mf::MultiFunction *get_multi_function(const bNode &bnode) diff --git a/source/blender/nodes/function/nodes/node_fn_integer_math.cc b/source/blender/nodes/function/nodes/node_fn_integer_math.cc index fdda05a49ed..7e739a7a351 100644 --- a/source/blender/nodes/function/nodes/node_fn_integer_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_integer_math.cc @@ -99,14 +99,17 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -static void node_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen) +static void node_label(const bNodeTree * /*ntree*/, + const bNode *node, + char *label, + int label_maxncpy) { const char *name; bool enum_label = RNA_enum_name(rna_enum_node_integer_math_items, node->custom1, &name); if (!enum_label) { name = CTX_N_(BLT_I18NCONTEXT_ID_NODETREE, "Unknown"); } - BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), maxlen); + BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), label_maxncpy); } /* Derived from `divide_round_i` but fixed to be safe and handle negative inputs. */ diff --git a/source/blender/python/intern/bpy_utils_units.cc b/source/blender/python/intern/bpy_utils_units.cc index a0b0349fad0..c0bc5742cfb 100644 --- a/source/blender/python/intern/bpy_utils_units.cc +++ b/source/blender/python/intern/bpy_utils_units.cc @@ -203,11 +203,11 @@ static PyObject *bpyunits_to_value(PyObject * /*self*/, PyObject *args, PyObject return nullptr; } - str_len = str_len * 2 + 64; - str = static_cast(PyMem_MALLOC(sizeof(*str) * size_t(str_len))); - BLI_strncpy(str, inpt, size_t(str_len)); + const size_t str_maxncpy = str_len * 2 + 64; + str = static_cast(PyMem_MALLOC(sizeof(*str) * str_maxncpy)); + BLI_strncpy(str, inpt, str_maxncpy); - BKE_unit_replace_string(str, int(str_len), uref, scale, usys, ucat); + BKE_unit_replace_string(str, int(str_maxncpy), uref, scale, usys, ucat); if (!PyC_RunString_AsNumber(nullptr, str, "", &result)) { if (PyErr_Occurred()) {