Skip to content

Commit 19cafc6

Browse files
committed
test: Replace remaining sprintf with snprintf
Use of `sprintf` is seen as a red flag as many of its uses are insecure. OpenBSD warns about it while compiling, and some modern platforms, e.g. [cloudlibc from cloudabi](https://github.com/NuxiNL/cloudlibc) don't even provide it anymore. Although our uses of these functions are secure, it can't hurt to replace them anyway. There are only 3 occurences left, all in the tests.
1 parent 0a17714 commit 19cafc6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/test/dbwrapper_tests.cpp

Lines changed: 3 additions & 3 deletions
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;

0 commit comments

Comments
 (0)