From 04975b4ef366f9d4a13d45ccc738cfb892b60aeb Mon Sep 17 00:00:00 2001 From: Muhammad Asim Jamshed Date: Sun, 24 May 2020 03:02:05 -0700 Subject: [PATCH] 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 Signed-off-by: Saikrishna Edupuganti --- core/modules/wildcard_match.cc | 14 +++++++------- core/modules/wildcard_match.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/modules/wildcard_match.cc b/core/modules/wildcard_match.cc index 1b7bfeb6c..1b755d514 100644 --- a/core/modules/wildcard_match.cc +++ b/core/modules/wildcard_match.cc @@ -299,11 +299,11 @@ 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; } @@ -311,7 +311,7 @@ int WildcardMatch::DelEntry(int idx, wm_hkey_t *key) { tuples_.erase(tuples_.begin() + idx); } - return 0; + return true; } CommandResponse WildcardMatch::CommandAdd( @@ -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(); diff --git a/core/modules/wildcard_match.h b/core/modules/wildcard_match.h index 5a8d9e814..03fc79e92 100644 --- a/core/modules/wildcard_match.h +++ b/core/modules/wildcard_match.h @@ -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();