Skip to content

Commit

Permalink
DelEntry() fix in WildcardMatch module.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ajamshed committed May 25, 2020
1 parent 6786d37 commit 04975b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions core/modules/wildcard_match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,19 @@ int WildcardMatch::AddTuple(wm_hkey_t *mask) {
return int(tuples_.size() - 1);
}

int WildcardMatch::DelEntry(int idx, wm_hkey_t *key) {
bool WildcardMatch::DelEntry(int idx, wm_hkey_t *key) {
struct WmTuple &tuple = tuples_[idx];
int ret =
bool ret =
tuple.ht.Remove(*key, wm_hash(total_key_size_), wm_eq(total_key_size_));
if (ret) {
if (ret == false) {
return ret;
}

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

return 0;
return true;
}

CommandResponse WildcardMatch::CommandAdd(
Expand Down Expand Up @@ -368,9 +368,9 @@ CommandResponse WildcardMatch::CommandDelete(
return CommandFailure(-idx, "failed to delete a rule");
}

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

return CommandSuccess();
Expand Down
2 changes: 1 addition & 1 deletion core/modules/wildcard_match.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class WildcardMatch final : public Module {

int FindTuple(wm_hkey_t *mask);
int AddTuple(wm_hkey_t *mask);
int DelEntry(int idx, wm_hkey_t *key);
bool DelEntry(int idx, wm_hkey_t *key);

void Clear();

Expand Down

0 comments on commit 04975b4

Please sign in to comment.