[Bf-blender-cvs] [975194b237b] gsoc-2018-many-light-sampling: Fix restrict error in BLI_str_format_byte_unit
Campbell Barton
noreply at git.blender.org
Fri Jun 1 16:17:53 CEST 2018
Commit: 975194b237b0d61b0336644c79492a498f509fc5
Author: Campbell Barton
Date: Sun May 27 10:25:52 2018 +0200
Branches: gsoc-2018-many-light-sampling
https://developer.blender.org/rB975194b237b0d61b0336644c79492a498f509fc5
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.
*
More information about the Bf-blender-cvs
mailing list