diff mbox

[U-Boot] env: fix env var autocompletion

Message ID 20110404201745.3ffc30cb.kim.phillips@freescale.com
State Accepted
Commit af4d9074aa0ed7c0d62084af02a6967d69915de6
Headers show

Commit Message

Kim Phillips April 5, 2011, 1:17 a.m. UTC
commit 560d424b6d7cd4205b062ad95f1b104bd4f8bcc3 "env: re-add
support for auto-completion" fell short of its description -
the 'used' logic in hmatch_r was reversed - '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.

typing 'printenv tft' and hitting 'tab' now displays valid
choices for variable names.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Mike Frysinger <vapier@gentoo.org>
---
 lib/hashtable.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Mike Frysinger April 5, 2011, 1:53 a.m. UTC | #1
On Monday, April 04, 2011 21:17:45 Kim Phillips wrote:
> commit 560d424b6d7cd4205b062ad95f1b104bd4f8bcc3 "env: re-add
> support for auto-completion" fell short of its description -
> the 'used' logic in hmatch_r was reversed - '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.

i dont think my commit is wrong.  i think the bug you describe was actually 
added in c81c1222427f268d29ba999c82e2477c428e7bab.
-mike
Peter Barada April 5, 2011, 4:44 a.m. UTC | #2
> On Monday, April 04, 2011 21:17:45 Kim Phillips wrote:
>> commit 560d424b6d7cd4205b062ad95f1b104bd4f8bcc3 "env: re-add
>> support for auto-completion" fell short of its description -
>> the 'used' logic in hmatch_r was reversed - '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.
> i dont think my commit is wrong.  i think the bug you describe was actually 
> added in c81c1222427f268d29ba999c82e2477c428e7bab.
You're right; I accidentally inverted the condition in my patch; it orignally was:

    if (!htab->table[idx].used)
        continue;

Since a deleted entry is now -1 (and an unused entry is zero), the condition should have been:

    if (htab->table[idx].used <= 0)
        continue;

not:

    if (htab->table[idx].used > 0)
        continue;
> -mike
diff mbox

Patch

diff --git a/lib/hashtable.c b/lib/hashtable.c
index fcdb53c..92eaa38 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -209,7 +209,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;