Skip to content

Commit 3e10ff6

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#9867: Replace remaining sprintf with snprintf
19cafc6 test: Replace remaining sprintf with snprintf (Wladimir J. van der Laan) 0a17714 uint256: replace sprintf with HexStr and reverse-iterator (Wladimir J. van der Laan) Tree-SHA512: 2ba1dd4d25e1cbfff4d67b2f483448aa7c34ab5c799cddd48ba5826e5fa6df425abe35e244aaf4c52db9fccfb4d2a25a14bb4597bf9d1fce95991f270da6bb26
1 parent 0d38c16 commit 3e10ff6

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/test/dbwrapper_tests.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
277277
CDBWrapper dbw(ph, (1 << 20), true, false, false);
278278
for (int x=0x00; x<10; ++x) {
279279
for (int y = 0; y < 10; y++) {
280-
sprintf(buf, "%d", x);
280+
snprintf(buf, sizeof(buf), "%d", x);
281281
StringContentsSerializer key(buf);
282282
for (int z = 0; z < y; z++)
283283
key += key;
@@ -293,12 +293,12 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
293293
seek_start = 0;
294294
else
295295
seek_start = 5;
296-
sprintf(buf, "%d", seek_start);
296+
snprintf(buf, sizeof(buf), "%d", seek_start);
297297
StringContentsSerializer seek_key(buf);
298298
it->Seek(seek_key);
299299
for (int x=seek_start; x<10; ++x) {
300300
for (int y = 0; y < 10; y++) {
301-
sprintf(buf, "%d", x);
301+
snprintf(buf, sizeof(buf), "%d", x);
302302
std::string exp_key(buf);
303303
for (int z = 0; z < y; z++)
304304
exp_key += exp_key;

src/uint256.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
2020
template <unsigned int BITS>
2121
std::string base_blob<BITS>::GetHex() const
2222
{
23-
char psz[sizeof(data) * 2 + 1];
24-
for (unsigned int i = 0; i < sizeof(data); i++)
25-
sprintf(psz + i * 2, "%02x", data[sizeof(data) - i - 1]);
26-
return std::string(psz, psz + sizeof(data) * 2);
23+
return HexStr(std::reverse_iterator<const uint8_t*>(data + sizeof(data)), std::reverse_iterator<const uint8_t*>(data));
2724
}
2825

2926
template <unsigned int BITS>

0 commit comments

Comments
 (0)