Fix: incorrect sizes of fixed size buffers, ensure valid UTF8

Correct code that was likely to truncate when copying strings and
correct the the size of fixed sized buffers.
This commit is contained in:
Campbell Barton
2025-07-26 12:07:27 +00:00
parent 24c965905e
commit 0531230a35
3 changed files with 8 additions and 8 deletions

View File

@@ -15,7 +15,7 @@
#include "BLI_assert.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BKE_collection.hh"
#include "BKE_layer.hh"
@@ -67,8 +67,8 @@ static std::string get_default_collection_name(const Object *object,
break;
}
char name[MAX_ID_NAME];
SNPRINTF(name, format, object->id.name + 2);
char name[MAX_ID_NAME - 2];
SNPRINTF_UTF8(name, format, object->id.name + 2);
return name;
}

View File

@@ -1158,7 +1158,7 @@ static wmOperatorStatus object_select_same_collection_exec(bContext *C, wmOperat
{
Main *bmain = CTX_data_main(C);
Collection *collection;
char collection_name[MAX_ID_NAME];
char collection_name[MAX_ID_NAME - 2];
/* passthrough if no objects are visible */
if (CTX_DATA_COUNT(C, visible_bases) == 0) {
@@ -1209,7 +1209,7 @@ void OBJECT_OT_select_same_collection(wmOperatorType *ot)
RNA_def_string(ot->srna,
"collection",
nullptr,
MAX_ID_NAME,
MAX_ID_NAME - 2,
"Collection",
"Name of the collection to select");
}

View File

@@ -4,7 +4,7 @@
#include "BLI_bounds.hh"
#include "BLI_color.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_vector.hh"
#include "BKE_curves.hh"
@@ -247,8 +247,8 @@ void SVGExporter::export_grease_pencil_objects(pugi::xml_node node, const int fr
pugi::xml_node ob_node = frame_node.append_child("g");
char obtxt[96];
SNPRINTF(obtxt, "blender_object.%s.%d", ob->id.name + 2, frame_number);
char obtxt[15 + (MAX_ID_NAME - 2) + 1 + 11 + 1]; /* Final +1 for the null terminator. */
SNPRINTF_UTF8(obtxt, "blender_object.%s.%d", ob->id.name + 2, frame_number);
std::string object_id = std::string(obtxt) + this->get_node_uuid_string();
ob_node.append_attribute("id").set_value(object_id.c_str());