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

Fix Array safeValue(at:) #278

Open
mak-s opened this issue Oct 25, 2021 · 0 comments
Open

Fix Array safeValue(at:) #278

mak-s opened this issue Oct 25, 2021 · 0 comments

Comments

@mak-s
Copy link
Contributor

mak-s commented Oct 25, 2021

Array extension safaValue(at:) method would crash if a negative index is used.

func safeValue(at index: Int) -> Element? {
if index < self.count {
return self[index]
} else {
return nil
}
}

Though it does not introduce any bug at present as there is only one occurrence of safeValue usage, in CardPartHistogramView, which does not use a negative index, the extension method would crash if a negative index is used.

for (index, entry) in barEntries.enumerated() {
showEntry(index: index, entry: entry, animated: animated, oldEntry: oldValue.safeValue(at: index))
}

Could we add a add a check for negative value to ensure that method work for all index values.
(fix available in branch: https://github.com/mak-s/CardParts/tree/array_index_out_of_range)

Also, CardParts code coverage is less. I'd like to add some Unit tests for existing classes available in CardParts.

  • Could you please let me know if I should create a new Issue for adding Unit tests.
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

No branches or pull requests

1 participant