Skip to content

Commit 04975b4

Browse files
committed
DelEntry() fix in WildcardMatch module.
This small patch fixes DelEntry routine that is invoked by CommandDelete() function. Hashtable's Remove function returns false on failure. The conditional expression that captures this event is incorrect (if condition in line 306 fails). This patch uses boolean variables to fix this issue. Signed-off-by: Muhammad Asim Jamshed <[email protected]> Signed-off-by: Saikrishna Edupuganti <[email protected]>
1 parent 6786d37 commit 04975b4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

core/modules/wildcard_match.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,19 @@ int WildcardMatch::AddTuple(wm_hkey_t *mask) {
299299
return int(tuples_.size() - 1);
300300
}
301301

302-
int WildcardMatch::DelEntry(int idx, wm_hkey_t *key) {
302+
bool WildcardMatch::DelEntry(int idx, wm_hkey_t *key) {
303303
struct WmTuple &tuple = tuples_[idx];
304-
int ret =
304+
bool ret =
305305
tuple.ht.Remove(*key, wm_hash(total_key_size_), wm_eq(total_key_size_));
306-
if (ret) {
306+
if (ret == false) {
307307
return ret;
308308
}
309309

310310
if (tuple.ht.Count() == 0) {
311311
tuples_.erase(tuples_.begin() + idx);
312312
}
313313

314-
return 0;
314+
return true;
315315
}
316316

317317
CommandResponse WildcardMatch::CommandAdd(
@@ -368,9 +368,9 @@ CommandResponse WildcardMatch::CommandDelete(
368368
return CommandFailure(-idx, "failed to delete a rule");
369369
}
370370

371-
int ret = DelEntry(idx, &key);
372-
if (ret < 0) {
373-
return CommandFailure(-ret, "failed to delete a rule");
371+
bool ret = DelEntry(idx, &key);
372+
if (ret == false) {
373+
return CommandFailure(-ENOENT, "failed to delete a rule");
374374
}
375375

376376
return CommandSuccess();

core/modules/wildcard_match.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class WildcardMatch final : public Module {
170170

171171
int FindTuple(wm_hkey_t *mask);
172172
int AddTuple(wm_hkey_t *mask);
173-
int DelEntry(int idx, wm_hkey_t *key);
173+
bool DelEntry(int idx, wm_hkey_t *key);
174174

175175
void Clear();
176176

0 commit comments

Comments
 (0)