return nullptr instead of out-of-range data

This commit is contained in:
Axel Kohlmeyer
2022-05-05 07:50:45 -04:00
parent 2b1716cb3a
commit 6c28b55c13
2 changed files with 12 additions and 6 deletions

View File

@ -113,7 +113,9 @@ class Modify : protected Pointers {
int find_fix(const std::string &);
// new API
Fix *get_fix_by_id(const std::string &) const;
Fix *get_fix_by_index(int idx) const { return fix[idx]; }
Fix *get_fix_by_index(int idx) const {
return ((idx >= 0) && (idx < nfix)) ? fix[idx] : nullptr;
}
const std::vector<Fix *> get_fix_by_style(const std::string &) const;
const std::vector<Fix *> &get_fix_list();
@ -127,7 +129,9 @@ class Modify : protected Pointers {
int find_compute(const std::string &);
// new API
Compute *get_compute_by_id(const std::string &) const;
Compute *get_compute_by_index(int idx) const { return compute[idx]; }
Compute *get_compute_by_index(int idx) const {
return ((idx >= 0) && (idx < nfix)) ? compute[idx] : nullptr;
}
const std::vector<Compute *> get_compute_by_style(const std::string &) const;
const std::vector<Compute *> &get_compute_list();