Skip to content

Commit

Permalink
Fix typos, UBs and warnings (ton-blockchain#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed Feb 28, 2023
1 parent 5a47495 commit 0578cb4
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 139 deletions.
8 changes: 6 additions & 2 deletions adnl/adnl-peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ void AdnlPeerPairImpl::alarm() {
}
if (retry_send_at_ && retry_send_at_.is_in_past()) {
retry_send_at_ = td::Timestamp::never();
send_messages_in(std::move(pending_messages_), false);
auto messages = std::move(pending_messages_);
pending_messages_.clear();
send_messages_in(std::move(messages), true);
}
alarm_timestamp().relax(next_dht_query_at_);
alarm_timestamp().relax(next_db_update_at_);
Expand Down Expand Up @@ -791,7 +793,9 @@ void AdnlPeerPairImpl::Conn::create_conn(td::actor::ActorId<AdnlPeerPairImpl> pe
void AdnlPeerPairImpl::conn_change_state(AdnlConnectionIdShort id, bool ready) {
if (ready) {
if (pending_messages_.size() > 0) {
send_messages_in(std::move(pending_messages_), true);
auto messages = std::move(pending_messages_);
pending_messages_.clear();
send_messages_in(std::move(messages), true);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions crypto/block/block-db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ void BlockDbImpl::get_block_by_id(ton::BlockId blk_id, bool need_data, td::Promi
}
}
promise(it->second);
return;
}
promise(td::Status::Error(-666, "block not found in database"));
}
Expand All @@ -642,6 +643,7 @@ void BlockDbImpl::get_state_by_id(ton::BlockId blk_id, bool need_data, td::Promi
}
}
promise(it->second);
return;
}
if (zerostate.not_null() && blk_id == zerostate->blk.id) {
LOG(DEBUG) << "get_state_by_id(): zerostate requested";
Expand All @@ -666,6 +668,7 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
if (it == state_info.end()) {
promise(td::Status::Error(
-666, std::string{"cannot obtain output queue info for block "} + blk_id.to_str() + " : cannot load state"));
return;
}
if (it->second->data.is_null()) {
LOG(DEBUG) << "loading data for state " << blk_id.to_str();
Expand All @@ -679,6 +682,7 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
if (it2 == block_info.end()) {
promise(td::Status::Error(-666, std::string{"cannot obtain output queue info for block "} + blk_id.to_str() +
" : cannot load block description"));
return;
}
vm::StaticBagOfCellsDbLazy::Options options;
auto res = vm::StaticBagOfCellsDbLazy::create(it->second->data.clone(), options);
Expand Down Expand Up @@ -707,10 +711,12 @@ void BlockDbImpl::get_out_queue_info_by_id(ton::BlockId blk_id, td::Promise<td::
if (it->second->blk.root_hash != state_root->get_hash().bits()) {
promise(td::Status::Error(
-668, std::string{"state for block "} + blk_id.to_str() + " is invalid : state root hash mismatch"));
return;
}
vm::CellSlice cs = vm::load_cell_slice(state_root);
if (!cs.have(64, 1) || cs.prefetch_ulong(32) != 0x9023afde) {
promise(td::Status::Error(-668, std::string{"state for block "} + blk_id.to_str() + " is invalid"));
return;
}
auto out_queue_info = cs.prefetch_ref();
promise(Ref<OutputQueueInfoDescr>{true, blk_id, it2->second->blk.root_hash.cbits(), state_root->get_hash().bits(),
Expand Down Expand Up @@ -758,6 +764,7 @@ void BlockDbImpl::save_new_block(ton::BlockIdExt id, td::BufferSlice data, int a
auto save_res = save_db_file(id.file_hash, data, FMode::chk_if_exists | FMode::overwrite | FMode::chk_file_hash);
if (save_res.is_error()) {
promise(std::move(save_res));
return;
}
auto sz = data.size();
auto lev = bb.alloc<log::NewBlock>(id.id, id.root_hash, id.file_hash, data.size(), authority & 0xff);
Expand All @@ -780,6 +787,7 @@ void BlockDbImpl::save_new_state(ton::BlockIdExt id, td::BufferSlice data, int a
auto save_res = save_db_file(id.file_hash, data, FMode::chk_if_exists | FMode::overwrite | FMode::chk_file_hash);
if (save_res.is_error()) {
promise(std::move(save_res));
return;
}
auto sz = data.size();
auto lev = bb.alloc<log::NewState>(id.id, id.root_hash, id.file_hash, data.size(), authority & 0xff);
Expand Down
6 changes: 4 additions & 2 deletions crypto/fift/words.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void interpret_make_pop(vm::Stack& stack) {
}

void interpret_is_string(vm::Stack& stack) {
stack.push_bool(stack.pop().type() == vm::StackEntry::t_string);
stack.push_bool(stack.pop_chk().type() == vm::StackEntry::t_string);
}

int make_utf8_char(char buffer[4], int x) {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ void interpret_atom_anon(vm::Stack& stack) {
}

void interpret_is_atom(vm::Stack& stack) {
stack.push_bool(stack.pop().is_atom());
stack.push_bool(stack.pop_chk().is_atom());
}

bool are_eqv(vm::StackEntry x, vm::StackEntry y) {
Expand All @@ -1307,11 +1307,13 @@ bool are_eqv(vm::StackEntry x, vm::StackEntry y) {
}

void interpret_is_eqv(vm::Stack& stack) {
stack.check_underflow(2);
auto y = stack.pop(), x = stack.pop();
stack.push_bool(are_eqv(std::move(x), std::move(y)));
}

void interpret_is_eq(vm::Stack& stack) {
stack.check_underflow(2);
auto y = stack.pop(), x = stack.pop();
stack.push_bool(x == y);
}
Expand Down
6 changes: 3 additions & 3 deletions crypto/func/abscode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void VarDescr::set_const(td::RefInt256 value) {
} else if (s > 0) {
val |= _NonZero | _Pos | _Finite;
} else if (!s) {
if (*int_const == 1) {
val |= _Bit;
}
//if (*int_const == 1) {
// val |= _Bit;
//}
val |= _Zero | _Neg | _Pos | _Finite | _Bool | _Bit;
}
if (val & _Finite) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/func/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ VarDescrList Op::fwd_analyze(VarDescrList values) {
res.emplace_back(i);
}
AsmOpList tmp;
func->compile(tmp, res, args); // abstract interpretation of res := f (args)
func->compile(tmp, res, args, where); // abstract interpretation of res := f (args)
int j = 0;
for (var_idx_t i : left) {
values.add_newval(i).set_value(res[j++]);
Expand Down
Loading

0 comments on commit 0578cb4

Please sign in to comment.