diff --git a/src/sparrowshell.cpp b/src/sparrowshell.cpp index c4a9d72..0cd0f16 100644 --- a/src/sparrowshell.cpp +++ b/src/sparrowshell.cpp @@ -72,8 +72,10 @@ void SparrowShell::update() } void SparrowShell::ShellBuffer::push(std::string s){ - if (m_buffer.size() >= m_size) + if (m_buffer.size() >= m_size){ m_buffer[m_zero_offset++] = s; + m_zero_offset %= m_size; + } else m_buffer.push_back(s); } diff --git a/src/sparrowshell.h b/src/sparrowshell.h index 1860ae1..8072886 100644 --- a/src/sparrowshell.h +++ b/src/sparrowshell.h @@ -36,11 +36,11 @@ private: class ShellBuffer{ private: std::vector m_buffer; - int m_zero_offset; + int m_zero_offset = 0; unsigned int m_size; public: ShellBuffer(int size):m_size(size){} - std::string& operator[](int i){return m_buffer[m_zero_offset+i%m_size];} + std::string& operator[](int i){return m_buffer[(m_zero_offset+i)%m_size];} void push(std::string); unsigned int size(){return m_size;} };