Commit: 12a9e9ae336c7d8d30d9e3f05eae67f14e2f5bb9
Author: Campbell Barton
Date:   Sun May 27 10:25:52 2018 +0200
Branches: master
https://developer.blender.org/rB12a9e9ae336c7d8d30d9e3f05eae67f14e2f5bb9

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.

===================================================================

M       source/blender/blenlib/intern/string.c

===================================================================

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.
  *

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to