Fix some more unlikely integer truncation

This commit is contained in:
FranciscoPombal 2020-02-27 12:38:25 +00:00 committed by Arvid Norberg
parent a647fd475e
commit 0eee042bf9
2 changed files with 5 additions and 5 deletions

View File

@ -465,7 +465,7 @@ namespace {
{ {
// pad files don't need a path element, we'll just store them // pad files don't need a path element, we'll just store them
// under the .pad directory // under the .pad directory
char cnt[10]; char cnt[11];
std::snprintf(cnt, sizeof(cnt), "%d", pad_file_cnt); std::snprintf(cnt, sizeof(cnt), "%d", pad_file_cnt);
path = combine_path(".pad", cnt); path = combine_path(".pad", cnt);
++pad_file_cnt; ++pad_file_cnt;

View File

@ -2387,7 +2387,7 @@ TORRENT_TEST(immutable_put)
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
char tok[10]; char tok[11];
std::snprintf(tok, sizeof(tok), "%02d", idx); std::snprintf(tok, sizeof(tok), "%02d", idx);
msg_args args; msg_args args;
@ -2418,7 +2418,7 @@ TORRENT_TEST(immutable_put)
TEST_EQUAL(put_immutable_item_keys[2].string_value(), "put"); TEST_EQUAL(put_immutable_item_keys[2].string_value(), "put");
span<const char> const v = put_immutable_item_keys[6].data_section(); span<const char> const v = put_immutable_item_keys[6].data_section();
TEST_EQUAL(v, span<char const>(flat_data)); TEST_EQUAL(v, span<char const>(flat_data));
char tok[10]; char tok[11];
std::snprintf(tok, sizeof(tok), "%02d", idx); std::snprintf(tok, sizeof(tok), "%02d", idx);
TEST_EQUAL(put_immutable_item_keys[5].string_value(), tok); TEST_EQUAL(put_immutable_item_keys[5].string_value(), tok);
if (put_immutable_item_keys[0].string_value() != "q" if (put_immutable_item_keys[0].string_value() != "q"
@ -2492,7 +2492,7 @@ TORRENT_TEST(mutable_put)
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
char tok[10]; char tok[11];
std::snprintf(tok, sizeof(tok), "%02d", idx); std::snprintf(tok, sizeof(tok), "%02d", idx);
msg_args args; msg_args args;
@ -2528,7 +2528,7 @@ TORRENT_TEST(mutable_put)
, std::string(sig.bytes.data(), signature::len)); , std::string(sig.bytes.data(), signature::len));
span<const char> const v = put_mutable_item_keys[10].data_section(); span<const char> const v = put_mutable_item_keys[10].data_section();
TEST_CHECK(v == itemv); TEST_CHECK(v == itemv);
char tok[10]; char tok[11];
std::snprintf(tok, sizeof(tok), "%02d", idx); std::snprintf(tok, sizeof(tok), "%02d", idx);
TEST_EQUAL(put_mutable_item_keys[9].string_value(), tok); TEST_EQUAL(put_mutable_item_keys[9].string_value(), tok);
if (put_mutable_item_keys[0].string_value() != "q" if (put_mutable_item_keys[0].string_value() != "q"