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

Bug in queue pop (documentation), can break queue.empty() #948

Closed
Brolaf-dev opened this issue Aug 27, 2024 · 1 comment
Closed

Bug in queue pop (documentation), can break queue.empty() #948

Brolaf-dev opened this issue Aug 27, 2024 · 1 comment
Assignees
Labels

Comments

@Brolaf-dev
Copy link

Brolaf-dev commented Aug 27, 2024

 //*************************************************************************
  /// Removes the oldest value from the back of the queue.
  /// Does nothing if the queue is already empty.
  /// If asserts or exceptions are enabled, throws an etl::queue_empty if the queue is empty.
  //*************************************************************************
        void pop()
        {
    #if defined(ETL_CHECK_PUSH_POP)
          ETL_ASSERT(!empty(), ETL_ERROR(queue_empty));
    #endif
          p_buffer[out].~T();
          del_out();
        }    
      
void del_out()
{
if (++out == CAPACITY) ETL_UNLIKELY
{
out = 0;
}
--current_size;
ETL_DECREMENT_DEBUG_COUNT
}

bool empty() const
{
return current_size == 0;
}

Either the function or the documentation here is incorrect, when calling pop on an empty queue it does not do nothing. It does lower the current_size by 1 resulting in current_size -1. This in turn causes empty to return false which is incorrect.

@ETLCPP ETLCPP deleted a comment Aug 27, 2024
@ETLCPP ETLCPP deleted a comment Aug 27, 2024
@jwellbelove jwellbelove self-assigned this Aug 29, 2024
@jwellbelove
Copy link
Contributor

I'm fixing queue & stack, but this issue with the use of ETL_ASSERT is more widespread and needs a more thorough library wide fix.

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

No branches or pull requests

2 participants