diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-10-23 21:48:50 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-10-23 21:48:50 -0400 |
commit | b0646cc1423d4ea28d68c84e38e90ba8a6cb4e29 (patch) | |
tree | 4429b11bc470572281744383acc05580202f9258 /src/common/container.c | |
parent | 2ecee3fce2179c6fe9f9c748522e417b887ee021 (diff) | |
parent | cb693ef56e5fcef2a6d1844cb71c849022628bd8 (diff) | |
download | tor-b0646cc1423d4ea28d68c84e38e90ba8a6cb4e29.tar.gz tor-b0646cc1423d4ea28d68c84e38e90ba8a6cb4e29.zip |
Merge remote-tracking branch 'origin/maint-0.2.2' into maint-0.2.3
Diffstat (limited to 'src/common/container.c')
-rw-r--r-- | src/common/container.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/common/container.c b/src/common/container.c index d92f825784..ede98eca5a 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -571,7 +571,28 @@ smartlist_bsearch_idx(const smartlist_t *sl, const void *key, int (*compare)(const void *key, const void **member), int *found_out) { - int hi = smartlist_len(sl) - 1, lo = 0, cmp, mid; + const int len = smartlist_len(sl); + int hi, lo, cmp, mid; + + if (len == 0) { + *found_out = 0; + return 0; + } else if (len == 1) { + cmp = compare(key, (const void **) &sl->list[0]); + if (cmp == 0) { + *found_out = 1; + return 0; + } else if (cmp < 0) { + *found_out = 0; + return 0; + } else { + *found_out = 0; + return 1; + } + } + + hi = smartlist_len(sl) - 1; + lo = 0; while (lo <= hi) { mid = (lo + hi) / 2; |