From 12a9e9ae336c7d8d30d9e3f05eae67f14e2f5bb9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 27 May 2018 10:25:52 +0200 Subject: 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. --- source/blender/blenlib/intern/string.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source/blender/blenlib') 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. * -- cgit v1.2.3