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:
Sergey Sharybin
2022-11-03 15:08:46 +01:00
parent 90805c9943
commit 74c293863d

View File

@@ -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);