FIXED: string buffers potentially too small to fit formatted write

Summary:
This fixes the following warnings when compiled with GCC7:

util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::DBGet(rocksdb::DB*, rocksdb::Transaction*, rocksdb::ReadOptions&, uint16_t, uint64_t, bool, uint64_t*, std::__cxx11::string*, bool*)’:
util/transaction_test_util.cc:75:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
 Status RandomTransactionInserter::DBGet(
        ^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:84:11: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
   snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::Verify(rocksdb::DB*, uint16_t, uint64_t, bool, rocksdb::Random64*)’:
util/transaction_test_util.cc:245:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
 Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
        ^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:268:13: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
     snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Closes https://github.com/facebook/rocksdb/pull/3295

Differential Revision: D6609411

Pulled By: maysamyabandeh

fbshipit-source-id: 33f0add471056eb59db2f8bd4366e6dfbb1a187d
main
Wouter Beek 7 years ago committed by Facebook Github Bot
parent f54d7f5fea
commit 58b841b356
  1. 10
      util/transaction_test_util.cc

@ -77,8 +77,9 @@ Status RandomTransactionInserter::DBGet(
uint64_t ikey, bool get_for_update, uint64_t* int_value, uint64_t ikey, bool get_for_update, uint64_t* int_value,
std::string* full_key, bool* unexpected_error) { std::string* full_key, bool* unexpected_error) {
Status s; Status s;
// four digits and zero end char // Five digits (since the largest uint16_t is 65535) plus the NUL
char prefix_buf[5]; // end char.
char prefix_buf[6];
// Pad prefix appropriately so we can iterate over each set // Pad prefix appropriately so we can iterate over each set
assert(set_i + 1 <= 9999); assert(set_i + 1 <= 9999);
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1); snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
@ -262,8 +263,9 @@ Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
} }
// For each set of keys with the same prefix, sum all the values // For each set of keys with the same prefix, sum all the values
for (uint16_t set_i : set_vec) { for (uint16_t set_i : set_vec) {
// four digits and zero end char // Five digits (since the largest uint16_t is 65535) plus the NUL
char prefix_buf[5]; // end char.
char prefix_buf[6];
assert(set_i + 1 <= 9999); assert(set_i + 1 <= 9999);
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1); snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
uint64_t total = 0; uint64_t total = 0;

Loading…
Cancel
Save