Skip to content

Commit e967187

Browse files
committed
Fixed DeepCode alert 'Using sprintf'
1 parent 52b6055 commit e967187

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/md5.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,16 @@ MD5& MD5::finalize()
334334
// return hex representation of digest as string
335335
std::string MD5::hexdigest() const
336336
{
337-
if (!finalized)
337+
if (!finalized) {
338338
return "";
339-
339+
}
340+
const std::string sHex = "0123456789abcdef";
340341
char buf[33];
341-
for (int i=0; i<16; i++)
342-
sprintf(buf+i*2, "%02x", digest[i]);
342+
for (int i = 0; i < 16; i++) {
343+
buf[i*2] = sHex[digest[i] >> 4 & 0x0F];
344+
buf[i*2+1] = sHex[digest[i] & 0x0F];
345+
}
343346
buf[32]=0;
344-
345347
return std::string(buf);
346348
}
347349

0 commit comments

Comments
 (0)