From 58b841b3568aec6f2f7489720135074dd709df7b Mon Sep 17 00:00:00 2001 From: Wouter Beek Date: Wed, 20 Dec 2017 08:02:53 -0800 Subject: [PATCH] FIXED: string buffers potentially too small to fit formatted write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- util/transaction_test_util.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/transaction_test_util.cc b/util/transaction_test_util.cc index bcda70514..e28832972 100644 --- a/util/transaction_test_util.cc +++ b/util/transaction_test_util.cc @@ -77,8 +77,9 @@ Status RandomTransactionInserter::DBGet( uint64_t ikey, bool get_for_update, uint64_t* int_value, std::string* full_key, bool* unexpected_error) { Status s; - // four digits and zero end char - char prefix_buf[5]; + // Five digits (since the largest uint16_t is 65535) plus the NUL + // end char. + char prefix_buf[6]; // Pad prefix appropriately so we can iterate over each set assert(set_i + 1 <= 9999); 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 (uint16_t set_i : set_vec) { - // four digits and zero end char - char prefix_buf[5]; + // Five digits (since the largest uint16_t is 65535) plus the NUL + // end char. + char prefix_buf[6]; assert(set_i + 1 <= 9999); snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1); uint64_t total = 0;