mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Cycles: Remove use of sprintf() in MD5 code
The new Xcode declares the `sprintf()` function deprecated and suggests to sue `snprintf()` as a safer alternative. This change actually moves away from any formatted printing and uses inlined byte-to-hex-string conversion which is also safe and is (unmesurably) faster. Differential Revision: https://developer.blender.org/D16378
This commit is contained in:
parent
90805c9943
commit
74c293863d
1 changed files with 7 additions and 2 deletions
|
|
@ -347,13 +347,18 @@ void MD5Hash::finish(uint8_t digest[16])
|
|||
|
||||
string MD5Hash::get_hex()
|
||||
{
|
||||
constexpr char kHexDigits[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
uint8_t digest[16];
|
||||
char buf[16 * 2 + 1];
|
||||
|
||||
finish(digest);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
sprintf(buf + i * 2, "%02X", (unsigned int)digest[i]);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
buf[i * 2 + 0] = kHexDigits[digest[i] / 0x10];
|
||||
buf[i * 2 + 1] = kHexDigits[digest[i] % 0x10];
|
||||
}
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
|
||||
return string(buf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue