Skip to content

Commit 36b407e

Browse files
laanwjfurszy
authored andcommitted
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 e8cb38a commit 36b407e

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
@@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
188188
CDBWrapper dbw(ph, (1 << 20), true, false);
189189
for (int x=0x00; x<10; ++x) {
190190
for (int y = 0; y < 10; y++) {
191-
sprintf(buf, "%d", x);
191+
snprintf(buf, sizeof(buf), "%d", x);
192192
StringContentsSerializer key(buf);
193193
for (int z = 0; z < y; z++)
194194
key += key;
@@ -204,12 +204,12 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
204204
seek_start = 0;
205205
else
206206
seek_start = 5;
207-
sprintf(buf, "%d", seek_start);
207+
snprintf(buf, sizeof(buf), "%d", seek_start);
208208
StringContentsSerializer seek_key(buf);
209209
it->Seek(seek_key);
210210
for (int x=seek_start; x<10; ++x) {
211211
for (int y = 0; y < 10; y++) {
212-
sprintf(buf, "%d", x);
212+
snprintf(buf, sizeof(buf), "%d", x);
213213
std::string exp_key(buf);
214214
for (int z = 0; z < y; z++)
215215
exp_key += exp_key;

0 commit comments

Comments
 (0)