From 0682af0d63a44b050d57bdaf7699e364a311d711 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Aug 2021 15:01:53 +1000 Subject: RNA: add length augmented to RNA_string_get_alloc This was noted as a TODO as it wraps RNA_property_string_get_alloc which takes a length return argument. --- source/blender/editors/space_buttons/buttons_ops.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/space_buttons') diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index c141789f171..798f4898aaa 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -198,7 +198,8 @@ static int file_browse_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); FileBrowseOp *fbo = op->customdata; ID *id; - char *str, path[FILE_MAX]; + char *str; + int str_len; const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; @@ -206,10 +207,11 @@ static int file_browse_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0); + str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0, &str_len); /* Add slash for directories, important for some properties. */ if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) { + char path[FILE_MAX]; const bool is_relative = RNA_boolean_get(op->ptr, "relative_path"); id = fbo->ptr.owner_id; @@ -220,13 +222,13 @@ static int file_browse_exec(bContext *C, wmOperator *op) /* Do this first so '//' isn't converted to '//\' on windows. */ BLI_path_slash_ensure(path); if (is_relative) { - BLI_strncpy(path, str, FILE_MAX); + const int path_len = BLI_strncpy_rlen(path, str, FILE_MAX); BLI_path_rel(path, BKE_main_blendfile_path(bmain)); - str = MEM_reallocN(str, strlen(path) + 2); + str = MEM_reallocN(str, path_len + 2); BLI_strncpy(str, path, FILE_MAX); } else { - str = MEM_reallocN(str, strlen(str) + 2); + str = MEM_reallocN(str, str_len + 2); } } else { -- cgit v1.2.3