Skip to content

Commit 8eb9623

Browse files
authored
Merge pull request #2269 from jamescowens/remove_sprintf
refactor: Remove sprintf and printf
2 parents 8f48d32 + c5d7d81 commit 8eb9623

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/gridcoin/scraper/scraper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
620620

621621
catch (std::exception& ex)
622622
{
623-
printf("Logger : exception occurred in _log function (%s)\n", ex.what());
623+
tfm::format(std::cerr, "Logger : exception occurred in _log function (%s)\n", ex.what());
624624

625625
return;
626626
}

src/gridcoin/upgrade.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,14 @@ void Upgrade::VerifySHA256SUM()
453453

454454
SHA256_Final(digest, &ctx);
455455

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

458-
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
459-
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
460-
461-
std::string FileSHA256SUM = {mdString};
458+
std::string FileSHA256SUM = HexStr(digest_vector);
462459

463460
if (ServerSHA256SUM == FileSHA256SUM)
464461
{
465-
LogPrint(BCLog::LogFlags::VERBOSE, "INFO %s: SHA256SUM verification successful.", __func__);
462+
LogPrint(BCLog::LogFlags::VERBOSE, "INFO %s: SHA256SUM verification successful (Server = %s, File = %s).",
463+
__func__, ServerSHA256SUM, FileSHA256SUM);
466464

467465
DownloadStatus.SetSHA256SUMProgress(100);
468466
DownloadStatus.SetSHA256SUMComplete(true);

src/test/getarg_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static bool ResetArgs(const std::string& strAddArg, const std::string& strArgIn
4141

4242
bool status = gArgs.ParseParameters(vecChar.size(), &vecChar[0], error);
4343

44-
if (!status) printf("ERROR: %s: %s", __func__, error.c_str());
44+
if (!status) tfm::format(std::cerr, "ERROR: %s: %s\n", __func__, error);
4545

4646
return status;
4747
}

src/test/gridcoin/superblock_tests.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ struct Legacy
133133
const char* chIn = s1.c_str();
134134
unsigned char digest2[16];
135135
MD5((unsigned char*)chIn, strlen(chIn), (unsigned char*)&digest2);
136-
char mdString2[33];
137-
for(int i = 0; i < 16; i++) {
138-
sprintf(&mdString2[i*2], "%02x", (unsigned int)digest2[i]);
139-
}
140-
std::string xmd5(mdString2);
141-
return xmd5;
136+
137+
const std::vector<unsigned char> digest_vector(digest2, digest2 + sizeof(digest2));
138+
139+
return HexStr(digest_vector);
142140
}
143141
catch (std::exception &e)
144142
{

0 commit comments

Comments
 (0)