diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-11-03 17:08:46 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-11-03 17:10:37 +0300 |
commit | 74c293863ded1c052601b4caed07efe3453d697d (patch) | |
tree | 0121a9de28be39ca4a7e5dc49806b0ff494adb3a /intern | |
parent | 90805c9943b3352c68a2b0e5121741751a2cf027 (diff) |
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
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/util/md5.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/intern/cycles/util/md5.cpp b/intern/cycles/util/md5.cpp index 1c7e6b9bf3e..3342d7a509a 100644 --- a/intern/cycles/util/md5.cpp +++ b/intern/cycles/util/md5.cpp @@ -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); |