[or-cvs] don"t assert multiple things in the same tor_assert()

Roger Dingledine arma at seul.org
Sat Oct 16 22:28:13 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common

Modified Files:
	crypto.c log.c torgzip.c tortls.c util.c 
Log Message:
don't assert multiple things in the same tor_assert()


Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- crypto.c	16 Oct 2004 20:38:56 -0000	1.112
+++ crypto.c	16 Oct 2004 22:28:11 -0000	1.113
@@ -325,7 +325,8 @@
 {
   BIO *b;
 
-  tor_assert(env && s);
+  tor_assert(env);
+  tor_assert(s);
 
   /* Create a read-only memory BIO, backed by the nul-terminated string 's' */
   b = BIO_new_mem_buf((char*)s, -1);
@@ -381,7 +382,9 @@
   BUF_MEM *buf;
   BIO *b;
 
-  tor_assert(env && env->key && dest);
+  tor_assert(env);
+  tor_assert(env->key);
+  tor_assert(dest);
 
   b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
 
@@ -414,7 +417,8 @@
 int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len) {
   BIO *b;
 
-  tor_assert(env && src);
+  tor_assert(env);
+  tor_assert(src);
 
   b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
 
@@ -479,7 +483,8 @@
 {
   int len;
   char buf[PK_BYTES*2]; /* Too long, but hey, stacks are big. */
-  tor_assert(env && out);
+  tor_assert(env);
+  tor_assert(out);
   len = crypto_pk_asn1_encode(env, buf, sizeof(buf));
   if (len < 0) {
     return -1;
@@ -563,7 +568,8 @@
 /** Return the size of the public key modulus in <b>env</b>, in bytes. */
 int crypto_pk_keysize(crypto_pk_env_t *env)
 {
-  tor_assert(env && env->key);
+  tor_assert(env);
+  tor_assert(env->key);
 
   return RSA_size(env->key);
 }
@@ -571,7 +577,8 @@
 /** Increase the reference count of <b>env</b>, and return it.
  */
 crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) {
-  tor_assert(env && env->key);
+  tor_assert(env);
+  tor_assert(env->key);
 
   env->refs++;
   return env;
@@ -585,7 +592,9 @@
 int crypto_pk_public_encrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding)
 {
   int r;
-  tor_assert(env && from && to);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
 
   r = RSA_public_encrypt(fromlen, (unsigned char*)from, to, env->key,
                             crypto_get_rsa_padding(padding));
@@ -604,7 +613,10 @@
 int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding, int warnOnFailure)
 {
   int r;
-  tor_assert(env && from && to && env->key);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
+  tor_assert(env->key);
   if (!env->key->p)
     /* Not a private key */
     return -1;
@@ -627,7 +639,9 @@
 int crypto_pk_public_checksig(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to)
 {
   int r;
-  tor_assert(env && from && to);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
   r = RSA_public_decrypt(fromlen, (unsigned char*)from, to, env->key, RSA_PKCS1_PADDING);
 
   if (r<0) {
@@ -645,7 +659,9 @@
 int crypto_pk_private_sign(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to)
 {
   int r;
-  tor_assert(env && from && to);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
   if (!env->key->p)
     /* Not a private key */
     return -1;
@@ -669,7 +685,9 @@
   char buf[PK_BYTES+1];
   int r;
 
-  tor_assert(env && data && sig);
+  tor_assert(env);
+  tor_assert(data);
+  tor_assert(sig);
 
   if (crypto_digest(data,datalen,digest)<0) {
     log_fn(LOG_WARN, "couldn't compute digest");
@@ -728,7 +746,9 @@
   crypto_cipher_env_t *cipher = NULL;
   char buf[PK_BYTES+1];
 
-  tor_assert(env && from && to);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
 
   overhead = crypto_get_rsa_padding_overhead(crypto_get_rsa_padding(padding));
   pkeylen = crypto_pk_keysize(env);
@@ -964,7 +984,8 @@
  */
 int crypto_cipher_set_key(crypto_cipher_env_t *env, const unsigned char *key)
 {
-  tor_assert(env && key);
+  tor_assert(env);
+  tor_assert(key);
 
   if (!env->key)
     return -1;
@@ -1009,7 +1030,11 @@
  */
 int crypto_cipher_encrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to)
 {
-  tor_assert(env && env->cipher && from && fromlen && to);
+  tor_assert(env);
+  tor_assert(env->cipher);
+  tor_assert(from);
+  tor_assert(fromlen);
+  tor_assert(to);
 
   aes_crypt(env->cipher, from, fromlen, to);
   return 0;
@@ -1021,7 +1046,9 @@
  */
 int crypto_cipher_decrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to)
 {
-  tor_assert(env && from && to);
+  tor_assert(env);
+  tor_assert(from);
+  tor_assert(to);
 
   aes_crypt(env->cipher, from, fromlen, to);
   return 0;
@@ -1054,7 +1081,8 @@
  */
 int crypto_digest(const unsigned char *m, int len, unsigned char *digest)
 {
-  tor_assert(m && digest);
+  tor_assert(m);
+  tor_assert(digest);
   return (SHA1(m,len,digest) == NULL);
 }
 
@@ -1105,7 +1133,8 @@
 {
   static char r[DIGEST_LEN];
   SHA_CTX tmpctx;
-  tor_assert(digest && out);
+  tor_assert(digest);
+  tor_assert(out);
   tor_assert(out_len <= DIGEST_LEN);
   /* memcpy into a temporary ctx, since SHA1_Final clears the context */
   memcpy(&tmpctx, &digest->d, sizeof(SHA_CTX));
@@ -1133,7 +1162,8 @@
 crypto_digest_assign(crypto_digest_env_t *into,
                      const crypto_digest_env_t *from)
 {
-  tor_assert(into && from);
+  tor_assert(into);
+  tor_assert(from);
   memcpy(into,from,sizeof(crypto_digest_env_t));
 }
 
@@ -1154,7 +1184,8 @@
 
   p = BN_new();
   g = BN_new();
-  tor_assert(p && g);
+  tor_assert(p);
+  tor_assert(g);
 
 #if 0
   /* This is from draft-ietf-ipsec-ike-modp-groups-05.txt.  It's a safe
@@ -1325,7 +1356,8 @@
  */
 void crypto_dh_free(crypto_dh_env_t *dh)
 {
-  tor_assert(dh && dh->dh);
+  tor_assert(dh);
+  tor_assert(dh->dh);
   DH_free(dh->dh);
   free(dh);
 }

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- log.c	23 Sep 2004 05:02:51 -0000	1.53
+++ log.c	16 Oct 2004 22:28:11 -0000	1.54
@@ -233,7 +233,8 @@
     logfiles = victim->next;
   else {
     for(tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ;
-    tor_assert(tmpl && tmpl->next == victim);
+    tor_assert(tmpl);
+    tor_assert(tmpl->next == victim);
     tmpl->next = victim->next;
   }
   tor_free(victim->filename);

Index: torgzip.c
===================================================================
RCS file: /home/or/cvsroot/src/common/torgzip.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- torgzip.c	14 Oct 2004 04:24:42 -0000	1.3
+++ torgzip.c	16 Oct 2004 22:28:11 -0000	1.4
@@ -53,7 +53,9 @@
   size_t out_size;
   off_t offset;
 
-  tor_assert(out && out_len && in);
+  tor_assert(out);
+  tor_assert(out_len);
+  tor_assert(in);
 
   if (method == GZIP_METHOD && !is_gzip_supported()) {
     /* Old zlib version don't support gzip in deflateInit2 */
@@ -136,7 +138,9 @@
   size_t out_size;
   off_t offset;
 
-  tor_assert(out && out_len && in);
+  tor_assert(out);
+  tor_assert(out_len);
+  tor_assert(in);
 
   if (method == GZIP_METHOD && !is_gzip_supported()) {
     /* Old zlib version don't support gzip in inflateInit2 */

Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- tortls.c	14 Oct 2004 03:18:13 -0000	1.67
+++ tortls.c	16 Oct 2004 22:28:11 -0000	1.68
@@ -191,7 +191,10 @@
 
   start_time = time(NULL);
 
-  tor_assert(rsa && cname && rsa_sign && cname_sign);
+  tor_assert(rsa);
+  tor_assert(cname);
+  tor_assert(rsa_sign);
+  tor_assert(cname_sign);
   if (!(sign_pkey = _crypto_pk_env_get_evp_pkey(rsa_sign,1)))
     goto error;
   if (!(pkey = _crypto_pk_env_get_evp_pkey(rsa,0)))
@@ -432,7 +435,8 @@
 tor_tls_read(tor_tls *tls, char *cp, size_t len)
 {
   int r, err;
-  tor_assert(tls && tls->ssl);
+  tor_assert(tls);
+  tor_assert(tls->ssl);
   tor_assert(tls->state == TOR_TLS_ST_OPEN);
   r = SSL_read(tls->ssl, cp, len);
   if (r > 0)
@@ -457,7 +461,8 @@
 tor_tls_write(tor_tls *tls, char *cp, size_t n)
 {
   int r, err;
-  tor_assert(tls && tls->ssl);
+  tor_assert(tls);
+  tor_assert(tls->ssl);
   tor_assert(tls->state == TOR_TLS_ST_OPEN);
   if (n == 0)
     return 0;
@@ -489,7 +494,8 @@
 tor_tls_handshake(tor_tls *tls)
 {
   int r;
-  tor_assert(tls && tls->ssl);
+  tor_assert(tls);
+  tor_assert(tls->ssl);
   tor_assert(tls->state == TOR_TLS_ST_HANDSHAKE);
   if (tls->isServer) {
     r = SSL_accept(tls->ssl);
@@ -512,7 +518,8 @@
 {
   int r, err;
   char buf[128];
-  tor_assert(tls && tls->ssl);
+  tor_assert(tls);
+  tor_assert(tls->ssl);
 
   while (1) {
     if (tls->state == TOR_TLS_ST_SENTCLOSE) {

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- util.c	16 Oct 2004 21:53:29 -0000	1.149
+++ util.c	16 Oct 2004 22:28:11 -0000	1.150
@@ -234,7 +234,9 @@
   char *destp;
   size_t len_in, len_out, len_ins;
   int is_even, remaining;
-  tor_assert(s && insert && n > 0);
+  tor_assert(s);
+  tor_assert(insert);
+  tor_assert(n > 0);
   len_in = strlen(s);
   len_ins = strlen(insert);
   len_out = len_in + (len_in/n)*len_ins;
@@ -487,7 +489,9 @@
  */
 void *smartlist_get(const smartlist_t *sl, int idx)
 {
-  tor_assert(sl && idx>=0 && idx < sl->num_used);
+  tor_assert(sl);
+  tor_assert(idx>=0);
+  tor_assert(idx < sl->num_used);
   return sl->list[idx];
 }
 /** Change the value of the <b>idx</b>th element of sl to <b>val</b>; return the old
@@ -496,7 +500,9 @@
 void *smartlist_set(smartlist_t *sl, int idx, void *val)
 {
   void *old;
-  tor_assert(sl && idx>=0 && idx < sl->num_used);
+  tor_assert(sl);
+  tor_assert(idx>=0);
+  tor_assert(idx < sl->num_used);
   old = sl->list[idx];
   sl->list[idx] = val;
   return old;
@@ -508,7 +514,9 @@
 void *smartlist_del(smartlist_t *sl, int idx)
 {
   void *old;
-  tor_assert(sl && idx>=0 && idx < sl->num_used);
+  tor_assert(sl);
+  tor_assert(idx>=0);
+  tor_assert(idx < sl->num_used);
   old = sl->list[idx];
   sl->list[idx] = sl->list[--sl->num_used];
   return old;
@@ -520,7 +528,9 @@
 void *smartlist_del_keeporder(smartlist_t *sl, int idx)
 {
   void *old;
-  tor_assert(sl && idx>=0 && idx < sl->num_used);
+  tor_assert(sl);
+  tor_assert(idx>=0);
+  tor_assert(idx < sl->num_used);
   old = sl->list[idx];
   --sl->num_used;
   if (idx < sl->num_used)
@@ -539,7 +549,9 @@
  */
 void smartlist_insert(smartlist_t *sl, int idx, void *val)
 {
-  tor_assert(sl && idx >= 0 && idx <= sl->num_used);
+  tor_assert(sl);
+  tor_assert(idx>=0);
+  tor_assert(idx < sl->num_used);
   if (idx == sl->num_used) {
     smartlist_add(sl, val);
   } else {
@@ -572,7 +584,9 @@
   const char *cp, *end, *next;
   int n = 0;
 
-  tor_assert(sl && str && sep);
+  tor_assert(sl);
+  tor_assert(str);
+  tor_assert(sep);
 
   cp = str;
   while (1) {
@@ -619,8 +633,9 @@
   int i;
   size_t n = 0, jlen;
   char *r = NULL, *dst, *src;
-  
-  tor_assert(sl && join);
+
+  tor_assert(sl);
+  tor_assert(join);
   jlen = strlen(join);
   for (i = 0; i < sl->num_used; ++i) {
     n += strlen(sl->list[i]);
@@ -681,7 +696,9 @@
   strmap_entry_t *resolve;
   strmap_entry_t search;
   void *oldval;
-  tor_assert(map && key && val);
+  tor_assert(map);
+  tor_assert(key);
+  tor_assert(val);
   search.key = (char*)key;
   resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
   if (resolve) {
@@ -704,7 +721,8 @@
 {
   strmap_entry_t *resolve;
   strmap_entry_t search;
-  tor_assert(map && key);
+  tor_assert(map);
+  tor_assert(key);
   search.key = (char*)key;
   resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
   if (resolve) {
@@ -725,7 +743,8 @@
   strmap_entry_t *resolve;
   strmap_entry_t search;
   void *oldval;
-  tor_assert(map && key);
+  tor_assert(map);
+  tor_assert(key);
   search.key = (char*)key;
   resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
   if (resolve) {
@@ -804,7 +823,8 @@
                     void *data)
 {
   strmap_entry_t *ptr, *next;
-  tor_assert(map && fn);
+  tor_assert(map);
+  tor_assert(fn);
   for (ptr = SPLAY_MIN(strmap_tree, &map->head); ptr != NULL; ptr = next) {
     /* This remove-in-place usage is specifically blessed in tree(3). */
     next = SPLAY_NEXT(strmap_tree, &map->head, ptr);
@@ -852,7 +872,8 @@
  */
 strmap_iter_t *strmap_iter_next(strmap_t *map, strmap_iter_t *iter)
 {
-  tor_assert(map && iter);
+  tor_assert(map);
+  tor_assert(iter);
   return SPLAY_NEXT(strmap_tree, &map->head, iter);
 }
 /** Advance the iterator <b>iter</b> a single step to the next entry, removing
@@ -861,7 +882,8 @@
 strmap_iter_t *strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter)
 {
   strmap_iter_t *next;
-  tor_assert(map && iter);
+  tor_assert(map);
+  tor_assert(iter);
   next = SPLAY_NEXT(strmap_tree, &map->head, iter);
   SPLAY_REMOVE(strmap_tree, &map->head, iter);
   tor_free(iter->key);
@@ -872,7 +894,9 @@
  */
 void strmap_iter_get(strmap_iter_t *iter, const char **keyp, void **valp)
 {
-  tor_assert(iter && keyp && valp);
+  tor_assert(iter);
+  tor_assert(keyp);
+  tor_assert(valp);
   *keyp = iter->key;
   *valp = iter->val;
 }
@@ -1069,7 +1093,8 @@
   int i;
   year = tm->tm_year + 1900;
   tor_assert(year >= 1970);
-  tor_assert(tm->tm_mon >= 0 && tm->tm_mon <= 11);
+  tor_assert(tm->tm_mon >= 0);
+  tor_assert(tm->tm_mon <= 11);
   days = 365 * (year-1970) + n_leapdays(1970,year);
   for (i = 0; i < tm->tm_mon; ++i)
     days += days_per_month[i];
@@ -1094,9 +1119,11 @@
   struct tm *tm = gmtime(&t);
 
   strftime(buf, RFC1123_TIME_LEN+1, "XXX, %d XXX %Y %H:%M:%S GMT", tm);
-  tor_assert(tm->tm_wday >= 0 && tm->tm_wday <= 6);
+  tor_assert(tm->tm_wday >= 0);
+  tor_assert(tm->tm_wday <= 6);
   memcpy(buf, WEEKDAY_NAMES[tm->tm_wday], 3);
-  tor_assert(tm->tm_wday >= 0 && tm->tm_mon <= 11);
+  tor_assert(tm->tm_wday >= 0);
+  tor_assert(tm->tm_mon <= 11);
   memcpy(buf+8, MONTH_NAMES[tm->tm_mon], 3);
 }
 
@@ -2010,7 +2037,8 @@
   return inet_aton(c, addr);
 #else
   uint32_t r;
-  tor_assert(c && addr);
+  tor_assert(c);
+  tor_assert(addr);
   if (strcmp(c, "255.255.255.255") == 0) {
     addr->s_addr = 0xFFFFFFFFu;
     return 1;
@@ -2132,8 +2160,12 @@
   struct in_addr in;
   int bits;
 
-  tor_assert(s && addr_out && mask_out && port_min_out && port_max_out);
-  
+  tor_assert(s);
+  tor_assert(addr_out);
+  tor_assert(mask_out);
+  tor_assert(port_min_out);
+  tor_assert(port_max_out);
+
   address = tor_strdup(s);
   /* Break 'address' into separate strings.
    */



More information about the tor-commits mailing list