aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-05-10 16:23:43 -0400
committerNick Mathewson <nickm@torproject.org>2011-05-11 16:12:51 -0400
commitdb7b2a33eef9c8d432442b072f9c8868a068bb91 (patch)
treece364a8c6abea10a8e21460cdc205f590cb820d5 /src/common
parent1d703ed22b249567c2df31db9035a4dda66483ca (diff)
downloadtor-db7b2a33eef9c8d432442b072f9c8868a068bb91.tar.gz
tor-db7b2a33eef9c8d432442b072f9c8868a068bb91.zip
Automated conversion of memcmp to tor_memcmp/tor_mem[n]eq
This commit is _exactly_ the result of perl -i -pe 's/\bmemcmp\(/tor_memcmp\(/g' src/*/*.[ch] perl -i -pe 's/\!\s*tor_memcmp\(/tor_memeq\(/g' src/*/*.[ch] perl -i -pe 's/0\s*==\s*tor_memcmp\(/tor_memeq\(/g' src/*/*.[ch] perl -i -pe 's/0\s*!=\s*tor_memcmp\(/tor_memneq\(/g' src/*/*.[ch] git checkout src/common/di_ops.[ch] git checkout src/or/test.c git checkout src/common/test.h
Diffstat (limited to 'src/common')
-rw-r--r--src/common/address.c2
-rw-r--r--src/common/compat.c2
-rw-r--r--src/common/container.c8
-rw-r--r--src/common/container.h4
-rw-r--r--src/common/crypto.c2
-rw-r--r--src/common/torgzip.c2
-rw-r--r--src/common/util.c10
7 files changed, 15 insertions, 15 deletions
diff --git a/src/common/address.c b/src/common/address.c
index 82a709601f..14f1d3f604 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -830,7 +830,7 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
const uint8_t *a2 = tor_addr_to_in6_addr8(addr2);
const int bytes = mbits >> 3;
const int leftover_bits = mbits & 7;
- if (bytes && (r = memcmp(a1, a2, bytes))) {
+ if (bytes && (r = tor_memcmp(a1, a2, bytes))) {
return r;
} else if (leftover_bits) {
uint8_t b1 = a1[bytes] >> (8-leftover_bits);
diff --git a/src/common/compat.c b/src/common/compat.c
index 333ef5b0f0..ea46d43d82 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -336,7 +336,7 @@ tor_memmem(const void *_haystack, size_t hlen,
while ((p = memchr(p, first, end-p))) {
if (p+nlen > end)
return NULL;
- if (!memcmp(p, needle, nlen))
+ if (tor_memeq(p, needle, nlen))
return p;
++p;
}
diff --git a/src/common/container.c b/src/common/container.c
index 977d604071..d1d5ce339d 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -215,7 +215,7 @@ smartlist_string_num_isin(const smartlist_t *sl, int num)
}
/** Return true iff <b>sl</b> has some element E such that
- * !memcmp(E,<b>element</b>,DIGEST_LEN)
+ * tor_memeq(E,<b>element</b>,DIGEST_LEN)
*/
int
smartlist_digest_isin(const smartlist_t *sl, const char *element)
@@ -223,7 +223,7 @@ smartlist_digest_isin(const smartlist_t *sl, const char *element)
int i;
if (!sl) return 0;
for (i=0; i < sl->num_used; i++)
- if (memcmp((const char*)sl->list[i],element,DIGEST_LEN)==0)
+ if (tor_memcmp((const char*)sl->list[i],element,DIGEST_LEN)==0)
return 1;
return 0;
}
@@ -663,7 +663,7 @@ smartlist_pqueue_assert_ok(smartlist_t *sl,
static int
_compare_digests(const void **_a, const void **_b)
{
- return memcmp((const char*)*_a, (const char*)*_b, DIGEST_LEN);
+ return tor_memcmp((const char*)*_a, (const char*)*_b, DIGEST_LEN);
}
/** Sort the list of DIGEST_LEN-byte digests into ascending order. */
@@ -716,7 +716,7 @@ strmap_entry_hash(const strmap_entry_t *a)
static INLINE int
digestmap_entries_eq(const digestmap_entry_t *a, const digestmap_entry_t *b)
{
- return !memcmp(a->key, b->key, DIGEST_LEN);
+ return tor_memeq(a->key, b->key, DIGEST_LEN);
}
/** Helper: return a hash value for a digest_map_t. */
diff --git a/src/common/container.h b/src/common/container.h
index 2b9f964f76..bb7cb89fc5 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -241,7 +241,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
* Example use:
* SMARTLIST_FOREACH_JOIN(routerstatus_list, routerstatus_t *, rs,
* routerinfo_list, routerinfo_t *, ri,
- * memcmp(rs->identity_digest, ri->identity_digest, 20),
+ * tor_memcmp(rs->identity_digest, ri->identity_digest, 20),
* log_info(LD_GENERAL,"No match for %s", ri->nickname)) {
* log_info(LD_GENERAL, "%s matches routerstatus %p", ri->nickname, rs);
* } SMARTLIST_FOREACH_JOIN_END(rs, ri);
@@ -256,7 +256,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
* ri = smartlist_get(routerinfo_list, ri_sl_idx);
* while (rs_sl_idx < rs_sl_len) {
* rs = smartlist_get(routerstatus_list, rs_sl_idx);
- * rs_ri_cmp = memcmp(rs->identity_digest, ri->identity_digest, 20);
+ * rs_ri_cmp = tor_memcmp(rs->identity_digest, ri->identity_digest, 20);
* if (rs_ri_cmp > 0) {
* break;
* } else if (rs_ri_cmp == 0) {
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 838347e20e..926942897f 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -845,7 +845,7 @@ crypto_pk_public_checksig_digest(crypto_pk_env_t *env, const char *data,
tor_free(buf);
return -1;
}
- if (memcmp(buf, digest, DIGEST_LEN)) {
+ if (tor_memcmp(buf, digest, DIGEST_LEN)) {
log_warn(LD_CRYPTO, "Signature mismatched with digest.");
tor_free(buf);
return -1;
diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 249151cc9b..51b29baca1 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -356,7 +356,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
compress_method_t
detect_compression_method(const char *in, size_t in_len)
{
- if (in_len > 2 && !memcmp(in, "\x1f\x8b", 2)) {
+ if (in_len > 2 && tor_memeq(in, "\x1f\x8b", 2)) {
return GZIP_METHOD;
} else if (in_len > 2 && (in[0] & 0x0f) == 8 &&
(ntohs(get_uint16(in)) % 31) == 0) {
diff --git a/src/common/util.c b/src/common/util.c
index f206d00c49..cb2cfed64d 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -459,7 +459,7 @@ strcmp_len(const char *s1, const char *s2, size_t s1_len)
return -1;
if (s1_len > s2_len)
return 1;
- return memcmp(s1, s2, s2_len);
+ return tor_memcmp(s1, s2, s2_len);
}
/** Compares the first strlen(s2) characters of s1 with s2. Returns as for
@@ -501,7 +501,7 @@ strcasecmpend(const char *s1, const char *s2)
/** Compare the value of the string <b>prefix</b> with the start of the
* <b>memlen</b>-byte memory chunk at <b>mem</b>. Return as for strcmp.
*
- * [As memcmp(mem, prefix, strlen(prefix)) but returns -1 if memlen is less
+ * [As tor_memcmp(mem, prefix, strlen(prefix)) but returns -1 if memlen is less
* than strlen(prefix).]
*/
int
@@ -511,7 +511,7 @@ memcmpstart(const void *mem, size_t memlen,
size_t plen = strlen(prefix);
if (memlen < plen)
return -1;
- return memcmp(mem, prefix, plen);
+ return tor_memcmp(mem, prefix, plen);
}
/** Return a pointer to the first char of s that is not whitespace and
@@ -644,14 +644,14 @@ tor_mem_is_zero(const char *mem, size_t len)
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
};
while (len >= sizeof(ZERO)) {
- if (memcmp(mem, ZERO, sizeof(ZERO)))
+ if (tor_memcmp(mem, ZERO, sizeof(ZERO)))
return 0;
len -= sizeof(ZERO);
mem += sizeof(ZERO);
}
/* Deal with leftover bytes. */
if (len)
- return ! memcmp(mem, ZERO, len);
+ return tor_memeq(mem, ZERO, len);
return 1;
}