From f6b151f16ded2a738310048755758e0f785bd654 Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Tue, 23 Oct 2018 22:12:21 -0700 Subject: [PATCH] fix clang analyzer error (#4583) Summary: clang analyzer currently fails with the following warnings: > db/log_reader.cc:323:9: warning: Undefined or garbage value returned to caller return r; ^~~~~~~~ db/log_reader.cc:344:11: warning: Undefined or garbage value returned to caller return r; ^~~~~~~~ db/log_reader.cc:369:11: warning: Undefined or garbage value returned to caller return r; Pull Request resolved: https://github.com/facebook/rocksdb/pull/4583 Differential Revision: D10523517 Pulled By: miasantreble fbshipit-source-id: 0cc8b8f27657b202bead148bbe7c4aa84fed095b --- db/log_reader.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/db/log_reader.cc b/db/log_reader.cc index d58540be3..6104ce32d 100644 --- a/db/log_reader.cc +++ b/db/log_reader.cc @@ -318,7 +318,10 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size) { while (true) { // We need at least the minimum header size if (buffer_.size() < static_cast(kHeaderSize)) { - int r; + // the default value of r is meaningless because ReadMore will overwrite + // it if it returns false; in case it returns true, the return value will + // not be used anyway + int r = kEof; if (!ReadMore(drop_size, &r)) { return r; } @@ -339,7 +342,7 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size) { header_size = kRecyclableHeaderSize; // We need enough for the larger header if (buffer_.size() < static_cast(kRecyclableHeaderSize)) { - int r; + int r = kEof; if (!ReadMore(drop_size, &r)) { return r; } @@ -364,7 +367,7 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size) { return kBadHeader; } } else { - int r; + int r = kEof; if (!ReadMore(drop_size, &r)) { return r; }