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

bounds checking in effect_set, effect_set_v #598

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions effectset.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ bool effect_sort_id(const effect* e1, const effect* e2);

struct effect_set {
void add_item(effect* peffect) {
if(count >= 64) return;
if (count >= 64)
return;
container[count++] = peffect;
}
void remove_item(int index) {
if(index >= count)
if (index < 0 || index >= count)
return;
if(index == count - 1) {
--count;
Expand All @@ -45,9 +46,11 @@ struct effect_set {
std::sort(container.begin(), container.begin() + count, effect_sort_id);
}
effect* const& get_last() const {
assert(count);
return container[count - 1];
}
effect*& get_last() {
assert(count);
return container[count - 1];
}
effect* const& operator[] (int index) const {
Expand All @@ -72,7 +75,7 @@ struct effect_set_v {
container.push_back(peffect);
}
void remove_item(int index) {
if(index >= (int)container.size())
if (index < 0 || index >= (int)container.size())
return;
container.erase(container.begin() + index);
}
Expand All @@ -89,9 +92,11 @@ struct effect_set_v {
std::sort(container.begin(), container.begin() + count, effect_sort_id);
}
effect* const& get_last() const {
assert(container.size());
return container.back();
}
effect*& get_last() {
assert(container.size());
return container.back();
}
effect* const& operator[] (int index) const {
Expand Down