Use size_t for length in replaycache_add_test_and_elapsed()

For consistency with the rest of buffer lengths in Tor.

See #8960
This commit is contained in:
Arlo Breault 2013-08-03 22:36:32 -07:00 committed by Nick Mathewson
parent 468e44a0ef
commit 506a01bda8
4 changed files with 28 additions and 28 deletions

View File

@ -1207,7 +1207,7 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
/* check for replay of PK-encrypted portion. */ /* check for replay of PK-encrypted portion. */
replay = replaycache_add_test_and_elapsed( replay = replaycache_add_test_and_elapsed(
intro_point->accepted_intro_rsa_parts, intro_point->accepted_intro_rsa_parts,
parsed_req->ciphertext, (int)parsed_req->ciphertext_len, parsed_req->ciphertext, parsed_req->ciphertext_len,
&elapsed); &elapsed);
if (replay) { if (replay) {

View File

@ -65,7 +65,7 @@ replaycache_new(time_t horizon, time_t interval)
STATIC int STATIC int
replaycache_add_and_test_internal( 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) time_t *elapsed)
{ {
int rv = 0; int rv = 0;
@ -73,7 +73,7 @@ replaycache_add_and_test_internal(
time_t *access_time; time_t *access_time;
/* sanity check */ /* 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" log_info(LD_BUG, "replaycache_add_and_test_internal() called with stupid"
" parameters; please fix this."); " parameters; please fix this.");
goto done; goto done;
@ -176,7 +176,7 @@ replaycache_scrub_if_needed_internal(time_t present, replaycache_t *r)
*/ */
int 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); 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 int
replaycache_add_test_and_elapsed( 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); return replaycache_add_and_test_internal(time(NULL), r, data, len, elapsed);
} }

View File

@ -46,7 +46,7 @@ replaycache_t * replaycache_new(time_t horizon, time_t interval);
*/ */
STATIC int replaycache_add_and_test_internal( 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); time_t *elapsed);
STATIC void replaycache_scrub_if_needed_internal( STATIC void replaycache_scrub_if_needed_internal(
time_t present, replaycache_t *r); time_t present, replaycache_t *r);
@ -57,9 +57,9 @@ STATIC void replaycache_scrub_if_needed_internal(
* replaycache_t methods * 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( 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); void replaycache_scrub_if_needed(replaycache_t *r);
#endif #endif

View File

@ -76,13 +76,13 @@ test_replaycache_miss(void)
result = result =
replaycache_add_and_test_internal(1200, r, test_buffer, replaycache_add_and_test_internal(1200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
/* poke the bad-parameter error case too */ /* poke the bad-parameter error case too */
result = result =
replaycache_add_and_test_internal(1200, NULL, test_buffer, replaycache_add_and_test_internal(1200, NULL, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
done: done:
@ -102,12 +102,12 @@ test_replaycache_hit(void)
result = result =
replaycache_add_and_test_internal(1200, r, test_buffer, replaycache_add_and_test_internal(1200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
result = result =
replaycache_add_and_test_internal(1300, r, test_buffer, replaycache_add_and_test_internal(1300, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 1); test_eq(result, 1);
done: done:
@ -127,17 +127,17 @@ test_replaycache_age(void)
result = result =
replaycache_add_and_test_internal(1200, r, test_buffer, replaycache_add_and_test_internal(1200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
result = result =
replaycache_add_and_test_internal(1300, r, test_buffer, replaycache_add_and_test_internal(1300, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 1); test_eq(result, 1);
result = result =
replaycache_add_and_test_internal(3000, r, test_buffer, replaycache_add_and_test_internal(3000, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
done: done:
@ -158,12 +158,12 @@ test_replaycache_elapsed(void)
result = result =
replaycache_add_and_test_internal(1200, r, test_buffer, replaycache_add_and_test_internal(1200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
result = result =
replaycache_add_and_test_internal(1300, r, test_buffer, replaycache_add_and_test_internal(1300, r, test_buffer,
(int)strlen(test_buffer), &elapsed); strlen(test_buffer), &elapsed);
test_eq(result, 1); test_eq(result, 1);
test_eq(elapsed, 100); test_eq(elapsed, 100);
@ -184,17 +184,17 @@ test_replaycache_noexpire(void)
result = result =
replaycache_add_and_test_internal(1200, r, test_buffer, replaycache_add_and_test_internal(1200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
result = result =
replaycache_add_and_test_internal(1300, r, test_buffer, replaycache_add_and_test_internal(1300, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 1); test_eq(result, 1);
result = result =
replaycache_add_and_test_internal(3000, r, test_buffer, replaycache_add_and_test_internal(3000, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 1); test_eq(result, 1);
done: done:
@ -215,12 +215,12 @@ test_replaycache_scrub(void)
/* Set up like in test_replaycache_hit() */ /* Set up like in test_replaycache_hit() */
result = result =
replaycache_add_and_test_internal(100, r, test_buffer, replaycache_add_and_test_internal(100, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 0); test_eq(result, 0);
result = result =
replaycache_add_and_test_internal(200, r, test_buffer, replaycache_add_and_test_internal(200, r, test_buffer,
(int)strlen(test_buffer), NULL); strlen(test_buffer), NULL);
test_eq(result, 1); test_eq(result, 1);
/* /*
@ -257,14 +257,14 @@ test_replaycache_future(void)
/* Set up like in test_replaycache_hit() */ /* Set up like in test_replaycache_hit() */
result = result =
replaycache_add_and_test_internal(100, r, test_buffer, replaycache_add_and_test_internal(100, r, test_buffer,
(int)strlen(test_buffer), &elapsed); strlen(test_buffer), &elapsed);
test_eq(result, 0); test_eq(result, 0);
/* elapsed should still be 0, since it wasn't written */ /* elapsed should still be 0, since it wasn't written */
test_eq(elapsed, 0); test_eq(elapsed, 0);
result = result =
replaycache_add_and_test_internal(200, r, test_buffer, replaycache_add_and_test_internal(200, r, test_buffer,
(int)strlen(test_buffer), &elapsed); strlen(test_buffer), &elapsed);
test_eq(result, 1); test_eq(result, 1);
/* elapsed should be the time since the last hit */ /* elapsed should be the time since the last hit */
test_eq(elapsed, 100); test_eq(elapsed, 100);
@ -275,7 +275,7 @@ test_replaycache_future(void)
*/ */
result = result =
replaycache_add_and_test_internal(150, r, test_buffer, replaycache_add_and_test_internal(150, r, test_buffer,
(int)strlen(test_buffer), &elapsed); strlen(test_buffer), &elapsed);
/* We should still get a hit */ /* We should still get a hit */
test_eq(result, 1); test_eq(result, 1);
/* ...but it shouldn't let us see a negative elapsed time */ /* ...but it shouldn't let us see a negative elapsed time */
@ -304,18 +304,18 @@ test_replaycache_realtime(void)
/* This should miss */ /* This should miss */
result = 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); test_eq(result, 0);
/* This should hit */ /* This should hit */
result = 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); test_eq(result, 1);
/* This should hit and return a small elapsed time */ /* This should hit and return a small elapsed time */
result = result =
replaycache_add_test_and_elapsed(r, test_buffer, replaycache_add_test_and_elapsed(r, test_buffer,
(int)strlen(test_buffer), &elapsed); strlen(test_buffer), &elapsed);
test_eq(result, 1); test_eq(result, 1);
test_assert(elapsed >= 0); test_assert(elapsed >= 0);
test_assert(elapsed <= 5); test_assert(elapsed <= 5);