[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Loops work better when they terminate. Non-terminating loo...
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv19257/src/common
Modified Files:
util.c
Log Message:
Loops work better when they terminate. Non-terminating loops are easier
to diagnose when they don't trash the stack.
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- util.c 3 Apr 2004 00:58:53 -0000 1.76
+++ util.c 3 Apr 2004 02:55:42 -0000 1.77
@@ -113,7 +113,8 @@
{
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_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_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;