From c6d54b503702fca054f999cdfbc5923c6824b53c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 19 Feb 2015 16:44:36 -0800 Subject: [PATCH] fix erroneous assert: cast kBlockSize (of type unsigned int) to "int" Summary: Otherwise, we would assert that an unsigned expression is always >= 0. The intent was to form a possibly negative number, and to assert that that value is always >= 0, but since one variable in the computation was unsigned, the result was guaranteed to be unsigned, too, rendering the assertion useless. Cast that unsigned variable to "int", so that all operands are signed, and thus so that the result can be negative. Test Plan: Run "make EXTRA_CXXFLAGS='-W -Wextra'" and see fewer errors. Reviewers: ljin, sdong, igor.sugak, igor Reviewed By: igor Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D33771 --- db/log_writer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/log_writer.cc b/db/log_writer.cc index df601a470..7ffb6d0b9 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -52,7 +52,7 @@ Status Writer::AddRecord(const Slice& slice) { } // Invariant: we never leave < kHeaderSize bytes in a block. - assert(kBlockSize - block_offset_ - kHeaderSize >= 0); + assert(kBlockSize - block_offset_ >= kHeaderSize); const size_t avail = kBlockSize - block_offset_ - kHeaderSize; const size_t fragment_length = (left < avail) ? left : avail;