diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-04-03 05:58:23 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-04-03 05:58:23 +0000 |
commit | f696fd98bfe80fbf76d9093b42fcb14b06b04f26 (patch) | |
tree | 291771778892de2e966c8ede190d5f684a94f978 /src/common/container.c | |
parent | 1aedf3daf57d9b67fe00f30720cae4b75d36822d (diff) | |
download | tor-f696fd98bfe80fbf76d9093b42fcb14b06b04f26.tar.gz tor-f696fd98bfe80fbf76d9093b42fcb14b06b04f26.zip |
Make smartlist_string_remove consistent with smartlist_string
svn:r3998
Diffstat (limited to 'src/common/container.c')
-rw-r--r-- | src/common/container.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/common/container.c b/src/common/container.c index f3077176cf..9b63911301 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -118,17 +118,18 @@ void smartlist_remove(smartlist_t *sl, void *element) { } } -/** If there are any string in sl equal to element, remove the first. +/** If there are any strings in sl equal to element, remove them. * Does not preserve order. */ void smartlist_string_remove(smartlist_t *sl, const char *element) { int i; - size_t len = smartlist_len(sl); - for (i = 0; i < len; ++i) { - if (!strcmp(element, smartlist_get(sl, i))) { - smartlist_del(sl, i); - return; + tor_assert(sl); + tor_assert(element); + for (i = 0; i < sl->num_used; ++i) { + if (!strcmp(element, sl->list[i]) { + sl->list[i] = sl->list[--sl->num_used]; /* swap with the end */ + i--; /* so we process the new i'th element */ } } } |