summaryrefslogtreecommitdiff
path: root/tests.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-02-24 10:16:56 -0800
committerJoshua Haberman <joshua@reverberate.org>2009-02-24 10:16:56 -0800
commita0a99811beda79ee873f46f1519d59ee2070f34e (patch)
treedc2f6341ffeeff21556f6aaf8f4984d60ac1ce13 /tests.c
parenta38b191e8dd18d838d60da6060fcc2ba23657138 (diff)
Removed bounds checking, for speed and simplicity.
Callers must always over-allocate their buffer by at least ten bytes. Since we will never read *more* than ten bytes, there is no need to do bounds checking inside the parsing code.
Diffstat (limited to 'tests.c')
-rw-r--r--tests.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/tests.c b/tests.c
index e429188..4277a19 100644
--- a/tests.c
+++ b/tests.c
@@ -9,7 +9,7 @@ void test_get_v_uint64_t()
char zero[] = {0x00};
char *zero_buf = zero;
uint64_t zero_val = 0;
- status = get_v_uint64_t(&zero_buf, zero_buf+sizeof(zero), &zero_val);
+ status = get_v_uint64_t(&zero_buf, &zero_val);
assert(status == PBSTREAM_STATUS_OK);
assert(zero_val == 0);
assert(zero_buf == zero + sizeof(zero));
@@ -17,34 +17,28 @@ void test_get_v_uint64_t()
char one[] = {0x01};
char *one_buf = one;
uint64_t one_val = 0;
- status = get_v_uint64_t(&one_buf, one_buf+sizeof(one), &one_val);
+ status = get_v_uint64_t(&one_buf, &one_val);
assert(status == PBSTREAM_STATUS_OK);
assert(one_val == 1);
char twobyte[] = {0xAC, 0x02};
char *twobyte_buf = twobyte;
uint64_t twobyte_val = 0;
- status = get_v_uint64_t(&twobyte_buf, twobyte_buf+sizeof(twobyte), &twobyte_val);
+ status = get_v_uint64_t(&twobyte_buf, &twobyte_val);
assert(status == PBSTREAM_STATUS_OK);
assert(twobyte_val == 300);
char ninebyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F};
char *ninebyte_buf = ninebyte;
uint64_t ninebyte_val = 0;
- status = get_v_uint64_t(&ninebyte_buf, ninebyte_buf+sizeof(ninebyte), &ninebyte_val);
+ status = get_v_uint64_t(&ninebyte_buf, &ninebyte_val);
assert(status == PBSTREAM_STATUS_OK);
assert(ninebyte_val == (1LL<<63));
- char overrun[] = {0x80, 0x01};
- char *overrun_buf = overrun;
- uint64_t overrun_val = 0;
- status = get_v_uint64_t(&overrun_buf, overrun_buf+sizeof(overrun)-1, &overrun_val);
- assert(status == PBSTREAM_STATUS_INCOMPLETE);
-
char tenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01};
char *tenbyte_buf = tenbyte;
uint64_t tenbyte_val = 0;
- status = get_v_uint64_t(&tenbyte_buf, tenbyte_buf+sizeof(tenbyte), &tenbyte_val);
+ status = get_v_uint64_t(&tenbyte_buf, &tenbyte_val);
assert(status == PBSTREAM_ERROR_UNTERMINATED_VARINT);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback