diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-05-27 11:25:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-05-27 11:28:04 +0300 |
commit | 12a9e9ae336c7d8d30d9e3f05eae67f14e2f5bb9 (patch) | |
tree | f1797c2c9fa50f9ec3189a5a7df547f8ac531ec1 /source/blender/blenlib/intern | |
parent | 7a0699db34aa20d96e317202fee7d1266ff3b274 (diff) |
Fix restrict error in BLI_str_format_byte_unit
Don't use sprintf to append a string to it's self.
Also correct BLI_str_rstrip_float_zero's return value.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/string.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index da9f5a817b5..49630347032 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -799,6 +799,7 @@ int BLI_str_rstrip_float_zero(char *str, const char pad) while (end_p != p && *end_p == '0') { *end_p = pad; end_p--; + totstrip++; } } } @@ -1022,13 +1023,13 @@ void BLI_str_format_byte_unit(char dst[15], long long int bytes, const bool base decimals = MAX2(order - 1, 0); /* Format value first, stripping away floating zeroes. */ - sprintf(dst, "%.*f", decimals, bytes_converted); - BLI_str_rstrip_float_zero(dst, '\0'); - /* Append unit. */ - sprintf(dst, "%s %s", dst, base_10 ? units_base_10[order] : units_base_2[order]); + const size_t dst_len = 15; + size_t len = BLI_snprintf_rlen(dst, dst_len, "%.*f", decimals, bytes_converted); + len -= (size_t)BLI_str_rstrip_float_zero(dst, '\0'); + dst[len++] = ' '; + BLI_strncpy(dst + len, base_10 ? units_base_10[order] : units_base_2[order], dst_len - len); } - /** * Find the ranges needed to split \a str into its individual words. * |