Skip to content

Commit b0f2265

Browse files
committed
[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp
Reapply #143236 after fixing the bug reported in #143236 (comment).
1 parent 7f74533 commit b0f2265

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ static bool fillRanges(MemoryBuffer *Code,
279279

280280
if (Offsets.empty())
281281
Offsets.push_back(0);
282-
if (Offsets.size() == 1 && Lengths.empty()) {
283-
Lengths.push_back(Sources.getFileOffset(Sources.getLocForEndOfFile(ID)) -
284-
Offsets[0]);
282+
const bool EmptyLengths = Lengths.empty();
283+
unsigned Length = 0;
284+
if (Offsets.size() == 1 && EmptyLengths) {
285+
Length = Sources.getFileOffset(Sources.getLocForEndOfFile(ID)) - Offsets[0];
285286
} else if (Offsets.size() != Lengths.size()) {
286287
errs() << "error: number of -offset and -length arguments must match.\n";
287288
return true;
@@ -292,7 +293,8 @@ static bool fillRanges(MemoryBuffer *Code,
292293
errs() << "error: offset " << Offset << " is outside the file\n";
293294
return true;
294295
}
295-
const auto Length = Lengths[I];
296+
if (!EmptyLengths)
297+
Length = Lengths[I];
296298
if (Offset + Length > Code->getBufferSize()) {
297299
errs() << "error: invalid length " << Length << ", offset + length ("
298300
<< Offset + Length << ") is outside the file.\n";

0 commit comments

Comments
 (0)