[or-cvs] minor tweaks to the smartlist operations
Roger Dingledine
arma at seul.org
Sat Dec 13 06:56:23 UTC 2003
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common
Modified Files:
util.c
Log Message:
minor tweaks to the smartlist operations
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- util.c 13 Dec 2003 01:42:44 -0000 1.44
+++ util.c 13 Dec 2003 06:56:21 -0000 1.45
@@ -88,13 +88,19 @@
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) {
More information about the tor-commits
mailing list