From 6673d445f57aac34035393cdbfefaf67249e1a34 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 6 Jun 2007 13:02:22 +0000 Subject: r13283@catbus: nickm | 2007-06-06 01:43:44 -0400 Fix up a couple of loops flagged by -Wunsafe-loop-optimizations so that they are more readable (and more amenable to compilation) svn:r10513 --- src/common/crypto.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/common') diff --git a/src/common/crypto.c b/src/common/crypto.c index bcb8a375a8..adf375bd83 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1494,14 +1494,12 @@ crypto_expand_key_material(const char *key_in, size_t key_in_len, tor_assert(key_out_len <= DIGEST_LEN*256); memcpy(tmp, key_in, key_in_len); - for (cp = key_out, i=0; key_out_len; - ++i, cp += DIGEST_LEN, key_out_len -= DIGEST_LEN) { + for (cp = key_out, i=0; cp < key_out+key_out_len; + ++i, cp += DIGEST_LEN) { tmp[key_in_len] = i; if (crypto_digest(digest, tmp, key_in_len+1)) goto err; - memcpy(cp, digest, MIN(DIGEST_LEN, key_out_len)); - if (key_out_len < DIGEST_LEN) - break; + memcpy(cp, digest, MIN(DIGEST_LEN, key_out_len-(cp-key_out))); } memset(tmp, 0, key_in_len+1); tor_free(tmp); -- cgit v1.2.3-54-g00ecf