Skip to content

Commit

Permalink
bugfix:
Browse files Browse the repository at this point in the history
  1) Binlog append will core when remain part less than kHeaderSize;
  2) slaveof parse parmater check;
  • Loading branch information
flabby committed Apr 8, 2016
1 parent a222310 commit 1025c52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ void SlaveofCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info)
} else if (cur_size == 2) {
have_offset_ = true;
std::string str_filenum = *it++;
if (!slash::string2l(str_filenum.data(), str_filenum.size(), &filenum_) && filenum_ < 0) {
if (!slash::string2l(str_filenum.data(), str_filenum.size(), &filenum_) || filenum_ < 0) {
res_.SetRes(CmdRes::kInvalidInt);
return;
}
std::string str_pro_offset = *it++;
if (!slash::string2l(str_pro_offset.data(), str_pro_offset.size(), &pro_offset_) && pro_offset_ < 0) {
if (!slash::string2l(str_pro_offset.data(), str_pro_offset.size(), &pro_offset_) || pro_offset_ < 0) {
res_.SetRes(CmdRes::kInvalidInt);
return;
}
Expand Down
8 changes: 7 additions & 1 deletion src/pika_binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,13 @@ Status Binlog::AppendBlank(slash::WritableFile *file, uint64_t len) {
}

// Append a msg which occupy the remain part of the last block
uint32_t n = (uint32_t) ((len % kBlockSize) - kHeaderSize);
// We simply increase the remain length to kHeaderSize when remain part < kHeaderSize
uint32_t n;
if (len % kBlockSize < kHeaderSize) {
n = 0;
} else {
n = (uint32_t) ((len % kBlockSize) - kHeaderSize);
}

char buf[kBlockSize];
buf[0] = static_cast<char>(n & 0xff);
Expand Down

0 comments on commit 1025c52

Please sign in to comment.