Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check code with static analyzers #2580

Closed
BorysTheDev opened this issue Feb 13, 2024 · 11 comments
Closed

Check code with static analyzers #2580

BorysTheDev opened this issue Feb 13, 2024 · 11 comments
Assignees

Comments

@BorysTheDev
Copy link
Contributor

BorysTheDev commented Feb 13, 2024

I will add here bugs that I found with static analysis

@BorysTheDev BorysTheDev self-assigned this Feb 13, 2024
@BorysTheDev
Copy link
Contributor Author

`void Scheduler::ScheduleFromRemote(FiberInterface* cntx) {
// This function is called from FiberInterface::ActivateOther from a remote scheduler.
// But the fiber belongs to this scheduler.
DCHECK(cntx->scheduler_ == this);

// If someone else holds the bit - give up on scheduling by this call.
// This should not happen as ScheduleFromRemote should be called under a WaitQueue lock.
if ((cntx->flags_.fetch_or(FiberInterface::kScheduleRemote, memory_order_acquire) &
FiberInterface::kScheduleRemote) == 1) {
LOG(DFATAL) << "Already scheduled remotely " << cntx->name();
return;
}`

if ((cntx->flags_.fetch_or(FiberInterface::kScheduleRemote, memory_order_acquire) & FiberInterface::kScheduleRemote) == 1) is always false

@BorysTheDev
Copy link
Contributor Author

BorysTheDev commented Mar 11, 2024

optional<Transaction::MultiMode> multi_mode = DeduceExecMode(state, exec_info, *script_mgr()); if (!multi_mode) return rb->SendError( "Dragonfly does not allow execution of a server-side Lua in Multi transaction");

condition is always false

@BorysTheDev

This comment was marked as outdated.

@romange
Copy link
Collaborator

romange commented Mar 11, 2024

@BorysTheDev we should integrate it into our codebase and our test runs :)

@BorysTheDev
Copy link
Contributor Author

BorysTheDev commented Mar 11, 2024

OpStatus OpSetId2(const OpArgs& op_args, string_view key, const streamID& sid) {
....
long long entries_added = -1;
....
if (entries_added != -1)

@BorysTheDev
Copy link
Contributor Author

size_t node_max_bytes = kStreamNodeMaxBytes;
if (node_max_bytes == 0 || node_max_bytes > STREAM_LISTPACK_MAX_SIZE)
node_max_bytes = STREAM_LISTPACK_MAX_SIZE;

@BorysTheDev

This comment was marked as outdated.

@BorysTheDev

This comment was marked as outdated.

@BorysTheDev
Copy link
Contributor Author

DCHECK(it == blocks_.begin() || it == blocks_.begin() || it->Size() * 2 >= block_size_);

duplication check, maybe a bug

@dranikpg
Copy link
Contributor

   if (!conn_state.subscribe_info->channels.empty()) {
     server_cntx->UnsubscribeAll(false);
   }

   if (conn_state.subscribe_info) { // always true
     DCHECK(!conn_state.subscribe_info->patterns.empty());
     server_cntx->PUnsubscribeAll(false);
   }

   DCHECK(!conn_state.subscribe_info);
 }

UnsubscribeAll can call conn_state.reset(), so how is it always true? 🤔

@BorysTheDev
Copy link
Contributor Author

I think it's a false positive, I haven't dived deep when I analyzed the static analysis results. You can hide the comment and I will know that I was wrong regarding it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants