aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-03 02:55:42 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-03 02:55:42 +0000
commit7451de5d9735e95be04d9e5613ae1118236e7668 (patch)
tree821c68d4a3e0be9f3b6d422dde8deeb9e1b2b64d
parentffc58cd91a82c62dbf80f2a64253fa5762b6a63a (diff)
downloadtor-7451de5d9735e95be04d9e5613ae1118236e7668.tar
tor-7451de5d9735e95be04d9e5613ae1118236e7668.tar.gz
Loops work better when they terminate. Non-terminating loops are easier
to diagnose when they don't trash the stack. svn:r1460
-rw-r--r--src/common/util.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 0b6c8d2c7..7a9301efb 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -113,7 +113,8 @@ void hex_encode(const char *from, int fromlen, char *to)
{
const unsigned char *fp = from;
static const char TABLE[] = "0123456789abcdef";
- while (fromlen) {
+ assert(from && fromlen>=0 && to);
+ while (fromlen--) {
*to++ = TABLE[*fp >> 4];
*to++ = TABLE[*fp & 7];
++fp;
@@ -219,11 +220,13 @@ void *smartlist_choose(smartlist_t *sl) {
void *smartlist_get(smartlist_t *sl, int idx)
{
+ assert(sl && idx>=0 && idx < sl->num_used);
return sl->list[idx];
}
void *smartlist_set(smartlist_t *sl, int idx, void *val)
{
void *old;
+ assert(sl && idx>=0 && idx < sl->num_used);
old = sl->list[idx];
sl->list[idx] = val;
return old;
@@ -231,6 +234,7 @@ void *smartlist_set(smartlist_t *sl, int idx, void *val)
void *smartlist_del(smartlist_t *sl, int idx)
{
void *old;
+ assert(sl && idx>=0 && idx < sl->num_used);
old = sl->list[idx];
sl->list[idx] = sl->list[--sl->num_used];
return old;