Skip to content

Commit 6c267a3

Browse files
pdillingerfacebook-github-bot
authored andcommitted
Improve some unreachable-after-loop code (facebook#13764)
Summary: in log_reader.cc. * `for (;;)` (with no matching break inside) should be more structurally recognizable to compilers as unreachable after compared to `while (true)` which compilers can treat as conditional for warning/error purposes because `true` might have come from a macro, etc. * Comment the `break` statements to indicate they are for the `switch` (not the `for`) * No code or annotation is apparently needed for the unreachable end of the non-void function, so just a comment Pull Request resolved: facebook#13764 Test Plan: CI Reviewed By: archang19 Differential Revision: D78135493 Pulled By: pdillinger fbshipit-source-id: e313435a846a6e15346acf40404f755be98ab09a
1 parent f9f7ad7 commit 6c267a3

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

db/log_reader.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
9595
uint64_t prospective_record_offset = 0;
9696

9797
Slice fragment;
98-
while (true) {
98+
for (;;) {
9999
uint64_t physical_record_offset = end_of_buffer_offset_ - buffer_.size();
100100
size_t drop_size = 0;
101101
const uint8_t record_type =
@@ -140,7 +140,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
140140
prospective_record_offset = physical_record_offset;
141141
scratch->assign(fragment.data(), fragment.size());
142142
in_fragmented_record = true;
143-
break;
143+
break; // switch
144144

145145
case kMiddleType:
146146
case kRecyclableMiddleType:
@@ -153,7 +153,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
153153
}
154154
scratch->append(fragment.data(), fragment.size());
155155
}
156-
break;
156+
break; // switch
157157

158158
case kLastType:
159159
case kRecyclableLastType:
@@ -171,7 +171,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
171171
first_record_read_ = true;
172172
return true;
173173
}
174-
break;
174+
break; // switch
175175

176176
case kSetCompressionType: {
177177
if (compression_type_record_read_) {
@@ -193,7 +193,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
193193
} else {
194194
InitCompression(compression_record);
195195
}
196-
break;
196+
break; // switch
197197
}
198198
case kPredecessorWALInfoType:
199199
case kRecyclePredecessorWALInfoType: {
@@ -210,7 +210,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
210210
MaybeVerifyPredecessorWALInfo(wal_recovery_mode, fragment,
211211
recorded_predecessor_wal_info);
212212
}
213-
break;
213+
break; // switch
214214
}
215215
case kUserDefinedTimestampSizeType:
216216
case kRecyclableUserDefinedTimestampSizeType: {
@@ -235,7 +235,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
235235
ReportCorruption(fragment.size(), s.getState());
236236
}
237237
}
238-
break;
238+
break; // switch
239239
}
240240

241241
case kBadHeader:
@@ -304,7 +304,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
304304
in_fragmented_record = false;
305305
scratch->clear();
306306
}
307-
break;
307+
break; // switch
308308

309309
case kBadRecordLen:
310310
if (eof_) {
@@ -337,7 +337,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
337337
in_fragmented_record = false;
338338
scratch->clear();
339339
}
340-
break;
340+
break; // switch
341341

342342
default: {
343343
if ((record_type & kRecordTypeSafeIgnoreMask) == 0) {
@@ -349,11 +349,11 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
349349
}
350350
in_fragmented_record = false;
351351
scratch->clear();
352-
break;
352+
break; // switch
353353
}
354354
}
355355
}
356-
return false;
356+
// unreachable
357357
}
358358

359359
void Reader::MaybeVerifyPredecessorWALInfo(

0 commit comments

Comments
 (0)