summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-12-13 06:56:21 +0000
committerRoger Dingledine <arma@torproject.org>2003-12-13 06:56:21 +0000
commit5458ca39e8fd0ef582f3ed690fa589e44daf5c6b (patch)
tree4955e67e088b2ceff13a60277129d958cc5ea406
parent911f155f94bfd0bbbd2c3720fbdabd580fca13f4 (diff)
downloadtor-5458ca39e8fd0ef582f3ed690fa589e44daf5c6b.tar.gz
tor-5458ca39e8fd0ef582f3ed690fa589e44daf5c6b.zip
minor tweaks to the smartlist operations
svn:r903
-rw-r--r--src/common/util.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 11609e256a..dcce69bc15 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -88,13 +88,19 @@ void smartlist_free(smartlist_t *sl) {
void smartlist_add(smartlist_t *sl, void *element) {
if(sl->num_used < sl->max)
sl->list[sl->num_used++] = element;
+ else
+ log_fn(LOG_WARN,"We've already got %d elements, discarding.",sl->max);
}
void smartlist_remove(smartlist_t *sl, void *element) {
int i;
+ if(element == NULL)
+ return;
for(i=0; i < sl->num_used; i++)
- if(sl->list[i] == element)
+ if(sl->list[i] == element) {
sl->list[i] = sl->list[--sl->num_used]; /* swap with the end */
+ i--; /* so we process the new i'th element */
+ }
}
void *smartlist_choose(smartlist_t *sl) {