commit 506a01bda8fd6f055ff1deef0e73036f8031e7a4
Author: Arlo Breault <arlolra(a)gmail.com>
Date: Sat Aug 3 22:36:32 2013 -0700
Use size_t for length in replaycache_add_test_and_elapsed()
For consistency with the rest of buffer lengths in Tor.
See #8960
---
src/or/rendservice.c | 2 +-
src/or/replaycache.c | 8 ++++----
src/or/replaycache.h | 6 +++---
src/test/test_replay.c | 40 ++++++++++++++++++++--------------------
4 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index a8f63dd..061efe6 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -1207,7 +1207,7 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
/* check for replay of PK-encrypted portion. */
replay = replaycache_add_test_and_elapsed(
intro_point->accepted_intro_rsa_parts,
- parsed_req->ciphertext, (int)parsed_req->ciphertext_len,
+ parsed_req->ciphertext, parsed_req->ciphertext_len,
&elapsed);
if (replay) {
diff --git a/src/or/replaycache.c b/src/or/replaycache.c
index 122efb7..90f87c1 100644
--- a/src/or/replaycache.c
+++ b/src/or/replaycache.c
@@ -65,7 +65,7 @@ replaycache_new(time_t horizon, time_t interval)
STATIC int
replaycache_add_and_test_internal(
- time_t present, replaycache_t *r, const void *data, int len,
+ time_t present, replaycache_t *r, const void *data, size_t len,
time_t *elapsed)
{
int rv = 0;
@@ -73,7 +73,7 @@ replaycache_add_and_test_internal(
time_t *access_time;
/* sanity check */
- if (present <= 0 || !r || !data || len <= 0) {
+ if (present <= 0 || !r || !data || len == 0) {
log_info(LD_BUG, "replaycache_add_and_test_internal() called with stupid"
" parameters; please fix this.");
goto done;
@@ -176,7 +176,7 @@ replaycache_scrub_if_needed_internal(time_t present, replaycache_t *r)
*/
int
-replaycache_add_and_test(replaycache_t *r, const void *data, int len)
+replaycache_add_and_test(replaycache_t *r, const void *data, size_t len)
{
return replaycache_add_and_test_internal(time(NULL), r, data, len, NULL);
}
@@ -187,7 +187,7 @@ replaycache_add_and_test(replaycache_t *r, const void *data, int len)
int
replaycache_add_test_and_elapsed(
- replaycache_t *r, const void *data, int len, time_t *elapsed)
+ replaycache_t *r, const void *data, size_t len, time_t *elapsed)
{
return replaycache_add_and_test_internal(time(NULL), r, data, len, elapsed);
}
diff --git a/src/or/replaycache.h b/src/or/replaycache.h
index c60c408..cd713fe 100644
--- a/src/or/replaycache.h
+++ b/src/or/replaycache.h
@@ -46,7 +46,7 @@ replaycache_t * replaycache_new(time_t horizon, time_t interval);
*/
STATIC int replaycache_add_and_test_internal(
- time_t present, replaycache_t *r, const void *data, int len,
+ time_t present, replaycache_t *r, const void *data, size_t len,
time_t *elapsed);
STATIC void replaycache_scrub_if_needed_internal(
time_t present, replaycache_t *r);
@@ -57,9 +57,9 @@ STATIC void replaycache_scrub_if_needed_internal(
* replaycache_t methods
*/
-int replaycache_add_and_test(replaycache_t *r, const void *data, int len);
+int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
int replaycache_add_test_and_elapsed(
- replaycache_t *r, const void *data, int len, time_t *elapsed);
+ replaycache_t *r, const void *data, size_t len, time_t *elapsed);
void replaycache_scrub_if_needed(replaycache_t *r);
#endif
diff --git a/src/test/test_replay.c b/src/test/test_replay.c
index 200bf4d..b48f582 100644
--- a/src/test/test_replay.c
+++ b/src/test/test_replay.c
@@ -76,13 +76,13 @@ test_replaycache_miss(void)
result =
replaycache_add_and_test_internal(1200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
/* poke the bad-parameter error case too */
result =
replaycache_add_and_test_internal(1200, NULL, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
done:
@@ -102,12 +102,12 @@ test_replaycache_hit(void)
result =
replaycache_add_and_test_internal(1200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
result =
replaycache_add_and_test_internal(1300, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 1);
done:
@@ -127,17 +127,17 @@ test_replaycache_age(void)
result =
replaycache_add_and_test_internal(1200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
result =
replaycache_add_and_test_internal(1300, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 1);
result =
replaycache_add_and_test_internal(3000, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
done:
@@ -158,12 +158,12 @@ test_replaycache_elapsed(void)
result =
replaycache_add_and_test_internal(1200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
result =
replaycache_add_and_test_internal(1300, r, test_buffer,
- (int)strlen(test_buffer), &elapsed);
+ strlen(test_buffer), &elapsed);
test_eq(result, 1);
test_eq(elapsed, 100);
@@ -184,17 +184,17 @@ test_replaycache_noexpire(void)
result =
replaycache_add_and_test_internal(1200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
result =
replaycache_add_and_test_internal(1300, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 1);
result =
replaycache_add_and_test_internal(3000, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 1);
done:
@@ -215,12 +215,12 @@ test_replaycache_scrub(void)
/* Set up like in test_replaycache_hit() */
result =
replaycache_add_and_test_internal(100, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 0);
result =
replaycache_add_and_test_internal(200, r, test_buffer,
- (int)strlen(test_buffer), NULL);
+ strlen(test_buffer), NULL);
test_eq(result, 1);
/*
@@ -257,14 +257,14 @@ test_replaycache_future(void)
/* Set up like in test_replaycache_hit() */
result =
replaycache_add_and_test_internal(100, r, test_buffer,
- (int)strlen(test_buffer), &elapsed);
+ strlen(test_buffer), &elapsed);
test_eq(result, 0);
/* elapsed should still be 0, since it wasn't written */
test_eq(elapsed, 0);
result =
replaycache_add_and_test_internal(200, r, test_buffer,
- (int)strlen(test_buffer), &elapsed);
+ strlen(test_buffer), &elapsed);
test_eq(result, 1);
/* elapsed should be the time since the last hit */
test_eq(elapsed, 100);
@@ -275,7 +275,7 @@ test_replaycache_future(void)
*/
result =
replaycache_add_and_test_internal(150, r, test_buffer,
- (int)strlen(test_buffer), &elapsed);
+ strlen(test_buffer), &elapsed);
/* We should still get a hit */
test_eq(result, 1);
/* ...but it shouldn't let us see a negative elapsed time */
@@ -304,18 +304,18 @@ test_replaycache_realtime(void)
/* This should miss */
result =
- replaycache_add_and_test(r, test_buffer, (int)strlen(test_buffer));
+ replaycache_add_and_test(r, test_buffer, strlen(test_buffer));
test_eq(result, 0);
/* This should hit */
result =
- replaycache_add_and_test(r, test_buffer, (int)strlen(test_buffer));
+ replaycache_add_and_test(r, test_buffer, strlen(test_buffer));
test_eq(result, 1);
/* This should hit and return a small elapsed time */
result =
replaycache_add_test_and_elapsed(r, test_buffer,
- (int)strlen(test_buffer), &elapsed);
+ strlen(test_buffer), &elapsed);
test_eq(result, 1);
test_assert(elapsed >= 0);
test_assert(elapsed <= 5);