Skip to content

Commit

Permalink
Fixed newline in CURRENT file (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC authored Apr 11, 2021
1 parent 1d36104 commit 1a4ce5e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -917,13 +917,16 @@ Status VersionSet::Recover(bool *save_manifest) {
return s;
}
const size_t size = current.size();
if (size == 0 || (current[size - 1] != '\n' && current[size - 1] != '\r')) {
return Status::Corruption("CURRENT file does not end with newline");
}

int resizeSize = 1;
if (size >= 2 && current[size - 2] == '\r') {
resizeSize = 2;
if (size == 0) {
return Status::Corruption("CURRENT file is empty");
}

int resizeSize = 0;
while (current[size - resizeSize - 1] == '\n' || current[size - resizeSize - 1] == '\r') {
resizeSize += 1;
if (size <= resizeSize) {
return Status::Corruption("CURRENT file is empty");
}
}

current.resize(size - resizeSize);
Expand Down

0 comments on commit 1a4ce5e

Please sign in to comment.