- /* Test encoder limit enforcement. */
- for (i = 1; i < 0x8000000; i *= 2) {
- unsigned char *arr;
- unsigned int len;
-
- /* These should fit. */
- ok1(encode(i-1 + MIN_BLOCK_SIZE, false, array,
- encode_length(i-1)) == encode_length(i-1));
- ok1(encode(i + MIN_BLOCK_SIZE, false, array,
- encode_length(i)) == encode_length(i));
- ok1(encode(i+1 + MIN_BLOCK_SIZE, false, array,
- encode_length(i+1)) == encode_length(i+1));
-
- /* These should not: malloc so valgrind finds overruns. */
- len = encode_length(i-1) - 1;
- arr = malloc(len);
- ok1(encode(i-1 + MIN_BLOCK_SIZE, true, arr, len) == 0);
- free(arr);
-
- len = encode_length(i-1) - 1;
- arr = malloc(len);
- ok1(encode(i + MIN_BLOCK_SIZE, false, arr, len) == 0);
- free(arr);
-
- len = encode_length(i+1) - 1;
- arr = malloc(len);
- ok1(encode(i+1 + MIN_BLOCK_SIZE, false, arr, len) == 0);
- free(arr);
- }