[Bf-blender-cvs] [40e69a6] blender-v2.76a-release: Fix crash pressing +/- in file-selector

Campbell Barton noreply at git.blender.org
Thu Oct 29 11:39:37 CET 2015


Commit: 40e69a6e953e6a7180682bf2e820753da51572d3
Author: Campbell Barton
Date:   Fri Oct 16 04:57:52 2015 +1100
Branches: blender-v2.76a-release
https://developer.blender.org/rB40e69a6e953e6a7180682bf2e820753da51572d3

Fix crash pressing +/- in file-selector

Filenames over 128 chars would crash.
Move BLI_newname into file_ops,
this was only used in one place and isn't all that re-usable.
Also remove special behavior for 4 digits.

===================================================================

M	source/blender/blenlib/intern/path_util.c
M	source/blender/editors/space_file/file_ops.c

===================================================================

diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 902de79..951c88e 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -191,31 +191,6 @@ int BLI_split_name_num(char *left, int *nr, const char *name, const char delim)
 }
 
 /**
- * Looks for a string of digits within name (using BLI_stringdec) and adjusts it by add.
- */
-void BLI_newname(char *name, int add)
-{
-	char head[UNIQUE_NAME_MAX], tail[UNIQUE_NAME_MAX];
-	int pic;
-	unsigned short digits;
-	
-	pic = BLI_stringdec(name, head, tail, &digits);
-	
-	/* are we going from 100 -> 99 or from 10 -> 9 */
-	if (add < 0 && digits < 4 && digits > 0) {
-		int i, exp;
-		exp = 1;
-		for (i = digits; i > 1; i--) exp *= 10;
-		if (pic >= exp && (pic + add) < exp) digits--;
-	}
-	
-	pic += add;
-	
-	if (digits == 4 && pic < 0) pic = 0;
-	BLI_stringenc(name, head, tail, digits, pic);
-}
-
-/**
  * Ensures name is unique (according to criteria specified by caller in unique_check callback),
  * incrementing its numeric suffix as necessary. Returns true if name had to be adjusted.
  *
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 08b6564..328b09d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1973,6 +1973,37 @@ void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
 }
 
 
+/**
+ * Looks for a string of digits within name (using BLI_stringdec) and adjusts it by add.
+ */
+static void filenum_newname(char *name, size_t name_size, int add)
+{
+	char head[FILE_MAXFILE], tail[FILE_MAXFILE];
+	char name_temp[FILE_MAXFILE];
+	int pic;
+	unsigned short digits;
+
+	pic = BLI_stringdec(name, head, tail, &digits);
+
+	/* are we going from 100 -> 99 or from 10 -> 9 */
+	if (add < 0 && digits > 0) {
+		int i, exp;
+		exp = 1;
+		for (i = digits; i > 1; i--) {
+			exp *= 10;
+		}
+		if (pic >= exp && (pic + add) < exp) {
+			digits--;
+		}
+	}
+
+	pic += add;
+	if (pic < 0)
+		pic = 0;
+	BLI_stringenc(name_temp, head, tail, digits, pic);
+	BLI_strncpy(name, name_temp, name_size);
+}
+
 static int file_filenum_exec(bContext *C, wmOperator *op)
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
@@ -1980,7 +2011,7 @@ static int file_filenum_exec(bContext *C, wmOperator *op)
 	
 	int inc = RNA_int_get(op->ptr, "increment");
 	if (sfile->params && (inc != 0)) {
-		BLI_newname(sfile->params->file, inc);
+		filenum_newname(sfile->params->file, sizeof(sfile->params->file), inc);
 		ED_area_tag_redraw(sa);
 		file_draw_check(C);
 		// WM_event_add_notifier(C, NC_WINDOW, NULL);




More information about the Bf-blender-cvs mailing list