Skip to content

Commit e7883e5

Browse files
committed
fix: enforce const-correctness in indexed_vector
Signed-off-by: Kevin Vu <vietcgi@gmail.com>
1 parent bf60a61 commit e7883e5

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

userspace/engine/indexed_vector.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,32 @@ class indexed_vector {
8787
\brief Returns a pointer to the element at the given numeric index,
8888
or nullptr if no element exists at the given index.
8989
*/
90-
virtual inline T* at(size_t id) const {
90+
virtual inline const T* at(size_t id) const {
9191
if(id < m_entries.size()) {
92-
return (T* const)&m_entries[id];
92+
return &m_entries[id];
93+
}
94+
return nullptr;
95+
}
96+
97+
/*!
98+
\brief Returns a pointer to the element at the given numeric index,
99+
or nullptr if no element exists at the given index.
100+
*/
101+
virtual inline T* at(size_t id) {
102+
if(id < m_entries.size()) {
103+
return &m_entries[id];
104+
}
105+
return nullptr;
106+
}
107+
108+
/*!
109+
\brief Returns a pointer to the element at the given string index,
110+
or nullptr if no element exists at the given index.
111+
*/
112+
virtual inline const T* at(const std::string& index) const {
113+
auto it = m_index.find(index);
114+
if(it != m_index.end()) {
115+
return at(it->second);
93116
}
94117
return nullptr;
95118
}
@@ -98,7 +121,7 @@ class indexed_vector {
98121
\brief Returns a pointer to the element at the given string index,
99122
or nullptr if no element exists at the given index.
100123
*/
101-
virtual inline T* at(const std::string& index) const {
124+
virtual inline T* at(const std::string& index) {
102125
auto it = m_index.find(index);
103126
if(it != m_index.end()) {
104127
return at(it->second);

userspace/engine/rule_loader_compiler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,17 @@ static void build_rule_exception_infos(
153153
}
154154
}
155155

156-
static inline rule_loader::list_info* list_info_from_name(const rule_loader::collector& c,
157-
const std::string& name) {
156+
static inline const rule_loader::list_info* list_info_from_name(const rule_loader::collector& c,
157+
const std::string& name) {
158158
auto ret = c.lists().at(name);
159159
if(!ret) {
160160
throw falco_exception("can't find internal list info at name: " + name);
161161
}
162162
return ret;
163163
}
164164

165-
static inline rule_loader::macro_info* macro_info_from_name(const rule_loader::collector& c,
166-
const std::string& name) {
165+
static inline const rule_loader::macro_info* macro_info_from_name(const rule_loader::collector& c,
166+
const std::string& name) {
167167
auto ret = c.macros().at(name);
168168
if(!ret) {
169169
throw falco_exception("can't find internal macro info at name: " + name);

0 commit comments

Comments
 (0)