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

Append end index instead of array size as last index. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adenyes
Copy link

@adenyes adenyes commented Aug 12, 2021

closes #2
This repo is a translation from Matlab, which uses 1-based arrays. In Matlab, the array size and last index are the same.

When considering endpoints, the first and last index are appended to the "ind" vector. The bug was that the size was used instead of the last index, causing access beyond the end of the array.

In addition, the example code defines an array of 14 elements and populates 13 elements, hiding the bug if you try to test it with that code. This change corrects the size of the example array so that endpoints can be tested.

Before:

float inArr[14] = {0,1,1,1,1,1,1,5,1,1,1,1,1,7};
PeakFinder::findPeaks(in, out, false);
Maxima found:
5 

float inArr[14] = {0,1,1,1,1,1,1,5,1,1,1,1,1,7};
PeakFinder::findPeaks(in, out, true);
Maxima found:
5 0 

After

float inArr[14] = {0,1,1,1,1,1,1,5,1,1,1,1,1,7};
PeakFinder::findPeaks(in, out, false);
Maxima found:
5 

float inArr[14] = {0,1,1,1,1,1,1,5,1,1,1,1,1,7};
PeakFinder::findPeaks(in, out, true);
Maxima found:
5 7 

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.

endpoint bug
1 participant