Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-10-15 20:57:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-15 20:57:52 +0300
commit2f0db8015554d0fa80db58313f5b63b0355546f0 (patch)
tree003077f7e1bf5c689b230dfcdbdb648d685a721a /source/blender/editors/space_file/file_ops.c
parentcebaedd7094b547bc426c9a8acc83c950119441d (diff)
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.
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r--source/blender/editors/space_file/file_ops.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 8347ad87258..36572d6469d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2033,6 +2033,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);
@@ -2040,7 +2071,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);