Cleanup: use the suffix "_maxncpy" instead of "_len" for string sizes
The term "_len" is too easily confused with the strlen(), excluding the nil byte.
This commit is contained in:
@@ -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<GreasePencilLineartModifierData *>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1676,7 +1676,7 @@ blender::Vector<blender::StringRef> 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<blender::StringRef> 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<blender::StringRef> 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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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<char *>(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<char *>(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, "<bpy_units_api>", &result)) {
|
||||
if (PyErr_Occurred()) {
|
||||
|
||||
Reference in New Issue
Block a user