From 2705651565b7eae17d6d855421f178d08f28bfe9 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Wed, 27 Jul 2016 19:52:42 +0200 Subject: [PATCH] fix m_zero_offset init and update --- src/sparrowshell.cpp | 4 +++- src/sparrowshell.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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;} };