diff --git a/source/blender/blenkernel/intern/text.cc b/source/blender/blenkernel/intern/text.cc index b2ca1b6093f..83c0bd94761 100644 --- a/source/blender/blenkernel/intern/text.cc +++ b/source/blender/blenkernel/intern/text.cc @@ -127,9 +127,9 @@ static void text_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, const LISTBASE_FOREACH (TextLine *, line_src, &text_src->lines) { TextLine *line_dst = static_cast(MEM_mallocN(sizeof(*line_dst), __func__)); - line_dst->line = BLI_strdup(line_src->line); - line_dst->format = nullptr; + line_dst->line = BLI_strdupn(line_src->line, line_src->len); line_dst->len = line_src->len; + line_dst->format = nullptr; BLI_addtail(&text_dst->lines, line_dst); } diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index aa8c875e805..aebb2cb88bd 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -446,13 +446,13 @@ bool BLI_path_make_safe_filename_ex(char *filename, bool allow_tokens) #ifdef WIN32 { - const size_t len = strlen(filename); const char *invalid_names[] = { "con", "prn", "aux", "null", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", NULL, }; - char *filename_lower = BLI_strdup(filename); + const size_t len = strlen(filename); + char *filename_lower = BLI_strdupn(filename, len); const char **iname; /* Forbid trailing dot (trailing space has already been replaced above). */ diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index f90b7136a22..b765f05bf63 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -243,14 +243,15 @@ static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool o { ConsoleLine *ci = static_cast( MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add")); + const int str_len = strlen(str); if (own) { ci->line = str; } else { - ci->line = BLI_strdup(str); + ci->line = BLI_strdupn(str, str_len); } - ci->len = ci->len_alloc = strlen(str); + ci->len = ci->len_alloc = str_len; BLI_addtail(lb, ci); return ci; diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 1f603cb27da..3709f49532b 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -1530,8 +1530,8 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) } /* Put new_line in the `tmp->line` spot. */ - tmp->line = BLI_strdup(tmp_line); tmp->len = strlen(tmp_line); + tmp->line = BLI_strdupn(tmp_line, tmp->len); tmp->format = nullptr; } } diff --git a/source/blender/python/intern/bpy_app_translations.cc b/source/blender/python/intern/bpy_app_translations.cc index deebf4194f7..48fc9617518 100644 --- a/source/blender/python/intern/bpy_app_translations.cc +++ b/source/blender/python/intern/bpy_app_translations.cc @@ -242,7 +242,9 @@ static void _build_translations_cache(PyObject *py_messages, const char *locale) /* Do not overwrite existing keys! */ if (BPY_app_translations_py_pgettext(msgctxt, msgid) == msgid) { GHashKey *key = _ghashutil_keyalloc(msgctxt, msgid); - BLI_ghash_insert(_translations_cache, key, BLI_strdup(PyUnicode_AsUTF8(trans))); + Py_ssize_t trans_str_len; + const char *trans_str = PyUnicode_AsUTF8AndSize(trans, &trans_str_len); + BLI_ghash_insert(_translations_cache, key, BLI_strdupn(trans_str, trans_str_len)); } } } diff --git a/source/blender/python/intern/bpy_rna_operator.cc b/source/blender/python/intern/bpy_rna_operator.cc index 9c385a20907..752cd82b08b 100644 --- a/source/blender/python/intern/bpy_rna_operator.cc +++ b/source/blender/python/intern/bpy_rna_operator.cc @@ -33,7 +33,9 @@ static char *pyop_poll_message_get_fn(bContext * /*C*/, void *user_data) PyObject *py_func_or_msg = PyTuple_GET_ITEM(py_args, 0); if (PyUnicode_Check(py_func_or_msg)) { - return BLI_strdup(PyUnicode_AsUTF8(py_func_or_msg)); + Py_ssize_t msg_len; + const char *msg = PyUnicode_AsUTF8AndSize(py_func_or_msg, &msg_len); + return BLI_strdupn(msg, msg_len); } PyObject *py_args_after_first = PyTuple_GetSlice(py_args, 1, PY_SSIZE_T_MAX); @@ -52,7 +54,9 @@ static char *pyop_poll_message_get_fn(bContext * /*C*/, void *user_data) /* pass */ } else if (PyUnicode_Check(py_msg)) { - msg = BLI_strdup(PyUnicode_AsUTF8(py_msg)); + Py_ssize_t msg_src_len; + const char *msg_src = PyUnicode_AsUTF8AndSize(py_msg, &msg_src_len); + msg = BLI_strdupn(msg_src, msg_src_len); } else { PyErr_Format(PyExc_TypeError, diff --git a/source/blender/windowmanager/intern/wm_operator_type.cc b/source/blender/windowmanager/intern/wm_operator_type.cc index 63ec922aed4..cbb7e0b3557 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.cc +++ b/source/blender/windowmanager/intern/wm_operator_type.cc @@ -607,7 +607,7 @@ std::string WM_operatortype_description_or_name(bContext *C, if (text.empty()) { const std::string text_orig = WM_operatortype_name(ot, properties); if (!text_orig.empty()) { - text = BLI_strdup(text_orig.c_str()); + text = BLI_strdupn(text_orig.c_str(), text_orig.size()); } } return text;