Patchwork [U-Boot,v2] lib/hashtable: fix env var autocompletion

login
register
mail settings
Submitter Kim Phillips
Date April 5, 2011, 5:14 p.m.
Message ID <20110405121450.099cb324.kim.phillips@freescale.com>
Download mbox | patch
Permalink /patch/89904/
State Accepted
Headers show

Comments

Kim Phillips - April 5, 2011, 5:14 p.m.
commit c81c1222427f268d29ba999c82e2477c428e7bab "Fix hash
table deletion to prevent lost entries" broke environment
variable autocompletion by accidentally inverting the
condition for 'used' in hmatch_r().

'used' is 0 if the hash table entry is not used, or -1 if deleted.
This patch makes hmatch_r actually match on valid ('used') entries,
instead of skipping them and failing to match anything.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
---
v2: fix commit message to point to correct source of failure

 lib/hashtable.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Mike Frysinger - April 15, 2011, 7:57 a.m.
On Tuesday, April 05, 2011 13:14:50 Kim Phillips wrote:
> commit c81c1222427f268d29ba999c82e2477c428e7bab "Fix hash
> table deletion to prevent lost entries" broke environment
> variable autocompletion by accidentally inverting the
> condition for 'used' in hmatch_r().
> 
> 'used' is 0 if the hash table entry is not used, or -1 if deleted.
> This patch makes hmatch_r actually match on valid ('used') entries,
> instead of skipping them and failing to match anything.

blah, this started to annoy me quite a bit.  and your patch wfm.
Tested-by: Mike Frysinger <vapier@gentoo.org>
-mike
Wolfgang Denk - April 27, 2011, 10:55 p.m.
Dear Kim Phillips,

In message <20110405121450.099cb324.kim.phillips@freescale.com> you wrote:
> commit c81c1222427f268d29ba999c82e2477c428e7bab "Fix hash
> table deletion to prevent lost entries" broke environment
> variable autocompletion by accidentally inverting the
> condition for 'used' in hmatch_r().
> 
> 'used' is 0 if the hash table entry is not used, or -1 if deleted.
> This patch makes hmatch_r actually match on valid ('used') entries,
> instead of skipping them and failing to match anything.
> 
> Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> ---
> v2: fix commit message to point to correct source of failure

Applied, thanks.

Best regards,

Wolfgang Denk

Patch

diff --git a/lib/hashtable.c b/lib/hashtable.c
index 2788a65..19d5b15 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -232,7 +232,7 @@  int hmatch_r(const char *match, int last_idx, ENTRY ** retval,
 	size_t key_len = strlen(match);
 
 	for (idx = last_idx + 1; idx < htab->size; ++idx) {
-		if (htab->table[idx].used > 0)
+		if (htab->table[idx].used <= 0)
 			continue;
 		if (!strncmp(match, htab->table[idx].entry.key, key_len)) {
 			*retval = &htab->table[idx].entry;