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

Fixed some bugs #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fixed some bugs #1

wants to merge 2 commits into from

Conversation

BOND12
Copy link

@BOND12 BOND12 commented Jan 17, 2023

In the original version , the code:

#include <iostream>
using namespace std;

#include "RingBuffer.h"

RingBuffer<10, int> rb;

int main() {
	for (int i = 0; i < 8; ++i) {
		rb.Append(i);
	}

	while (rb.Available()) {
		cout << rb.Read(1).At(0) << endl;
		//rb.Skip(1);
	}



	return 0;
}

falls into an infinite loop, because the Read method does not move the buffer read pointer to the next position. This can be done using the Skip method, of course, but I think it's not right. I fixed it.
I also fixed the Skip method itself, because in the original version it did not control the input parameter to see if it could be more than the available amount of data to read. I corrected that too

If the skip method has to skip positions for reading more than written to the buffer, the buffer operation breaks, because read_position becomes larger than write_position.
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

Successfully merging this pull request may close these issues.

1 participant