diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-12-28 07:59:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-12-28 08:00:08 +0300 |
commit | 9686d3005cab50fbb3376ff1fd4c5e55b6a61b23 (patch) | |
tree | 98bcc3a94a83bbb777456f3f5510b42001d17d06 /source/blender/blenlib/intern/path_util.c | |
parent | 00197a668b3463ff050d224967407241a98486cb (diff) |
Fix buffer overrun calculating unique names
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 0a30a35ba7c..8b570189e29 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -228,7 +228,8 @@ bool BLI_uniquename_cb(bool (*unique_check)(void *arg, const char *name), int number; int len = BLI_split_name_num(left, &number, name, delim); do { - const int numlen = BLI_snprintf(numstr, sizeof(numstr), "%c%03d", delim, ++number); + /* add 1 to account for \0 */ + const int numlen = BLI_snprintf(numstr, sizeof(numstr), "%c%03d", delim, ++number) + 1; /* highly unlikely the string only has enough room for the number * but support anyway */ @@ -238,9 +239,8 @@ bool BLI_uniquename_cb(bool (*unique_check)(void *arg, const char *name), } else { char *tempname_buf; - tempname[0] = '\0'; - tempname_buf = BLI_strncat_utf8(tempname, left, name_len - numlen); - memcpy(tempname_buf, numstr, numlen + 1); + tempname_buf = tempname + BLI_strncpy_utf8_rlen(tempname, left, name_len - numlen); + memcpy(tempname_buf, numstr, numlen); } } while (unique_check(arg, tempname)); |