Skip to content

Commit

Permalink
Remove sprintf in upgrade.cpp and superblock_tests.cpp
Browse files Browse the repository at this point in the history
This replaces the sprintf with HexStr().
  • Loading branch information
jamescowens committed Aug 5, 2021
1 parent 8f48d32 commit aa83e6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/gridcoin/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,14 @@ void Upgrade::VerifySHA256SUM()

SHA256_Final(digest, &ctx);

char mdString[SHA256_DIGEST_LENGTH*2+1];
const std::vector<unsigned char> digest_vector(digest, digest + SHA256_DIGEST_LENGTH);

for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);

std::string FileSHA256SUM = {mdString};
std::string FileSHA256SUM = HexStr(digest_vector);

if (ServerSHA256SUM == FileSHA256SUM)
{
LogPrint(BCLog::LogFlags::VERBOSE, "INFO %s: SHA256SUM verification successful.", __func__);
LogPrint(BCLog::LogFlags::VERBOSE, "INFO %s: SHA256SUM verification successful (Server = %s, File = %s).",
__func__, ServerSHA256SUM, FileSHA256SUM);

DownloadStatus.SetSHA256SUMProgress(100);
DownloadStatus.SetSHA256SUMComplete(true);
Expand Down
10 changes: 4 additions & 6 deletions src/test/gridcoin/superblock_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,10 @@ struct Legacy
const char* chIn = s1.c_str();
unsigned char digest2[16];
MD5((unsigned char*)chIn, strlen(chIn), (unsigned char*)&digest2);
char mdString2[33];
for(int i = 0; i < 16; i++) {
sprintf(&mdString2[i*2], "%02x", (unsigned int)digest2[i]);
}
std::string xmd5(mdString2);
return xmd5;

const std::vector<unsigned char> digest_vector(digest2, digest2 + sizeof(digest2));

return HexStr(digest_vector);
}
catch (std::exception &e)
{
Expand Down

0 comments on commit aa83e6e

Please sign in to comment.