git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / helper / test-cache-entry.c
| 1 | #define USE_THE_REPOSITORY_VARIABLE |
| 2 | #include "test-tool.h" |
| 3 | #include "read-cache-ll.h" |
| 4 | |
| 5 | /* |
| 6 | * Exercise the cache-entry name-length guard without having to construct a |
| 7 | * multi-gigabyte pathname in memory. make_empty_cache_entry() |
| 8 | * dies on any length that would not survive being stored in the 32-bit |
| 9 | * "ce_namelen" field, and it does so before allocating, so an out-of-range |
| 10 | * length is cheap to test. |
| 11 | */ |
| 12 | int cmd__cache_entry(int argc, const char **argv) |
| 13 | { |
| 14 | size_t len; |
| 15 | char *end; |
| 16 | struct cache_entry *ce; |
| 17 | |
| 18 | if (argc != 2) |
| 19 | die("usage: test-tool cache-entry <namelen>"); |
| 20 | |
| 21 | errno = 0; |
| 22 | len = strtoumax(argv[1], &end, 10); |
| 23 | if (errno || *end) |
| 24 | die("cannot parse namelen '%s'", argv[1]); |
| 25 | |
| 26 | /* Dies here if 'len' is too large to be represented safely. */ |
| 27 | ce = make_empty_cache_entry(the_repository->index, len); |
| 28 | if (!ce) |
| 29 | die("failed to create cache entry"); |
| 30 | |
| 31 | printf("ok: allocated cache entry for namelen %"PRIuMAX"\n", |
| 32 | (uintmax_t)len); |
| 33 | discard_cache_entry(ce); |
| 34 | return 0; |
| 35 | } |