- avoid loop within loop for unique naming function (even though it wasnt likely...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 7 Nov 2010 09:33:10 +0000 (09:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 7 Nov 2010 09:33:10 +0000 (09:33 +0000)
- off by 1 error with outliner naming length. was 1 too short.

source/blender/blenlib/intern/path_util.c
source/blender/editors/space_outliner/outliner.c

index fffc74e..a496e6c 100644 (file)
@@ -205,10 +205,12 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons
                char    left[UNIQUE_NAME_MAX];
                int             number;
                int             len= BLI_split_name_num(left, &number, name, delim);
-               do {    /* nested while loop looks bad but likely it wont run most times */
-                       while(BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, number) >= name_len) {
-                               if(len > 0)     left[--len]= '\0';      /* word too long */
-                               else            number= 0;                      /* reset, must be a massive number */
+               do {
+                       int newlen= BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, number);
+                       if(newlen >= name_len) {
+                               len -= ((newlen + 1) - name_len);
+                               if(len < 0) len= number= 0;
+                               left[len]= '\0';
                        }
                } while(number++, unique_check(arg, tempname));
 
index a9b0dc8..4cd233d 100644 (file)
@@ -5592,7 +5592,7 @@ static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, Spa
                                spx=te->xs+2*OL_X-4;
                                if(spx+dx+10>ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax-spx-10;
 
-                               bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (short)te->ys, dx+10, OL_H-1, te->name, 1.0, (float)len-1, 0, 0, "");
+                               bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (short)te->ys, dx+10, OL_H-1, te->name, 1.0, (float)len, 0, 0, "");
                                uiButSetRenameFunc(bt, namebutton_cb, tselem);
                                
                                /* returns false if button got removed */