* Decompress zstream from the standard input into a newly * allocated buffer of specified size and return the buffer. * The caller is responsible to free the returned buffer. * * But for dry_run mode, "get_data()" is only used to check the * integrity of data, and the returned buffer is not used at all. * Therefore, in dry_run mode, "get_data()" will release the small * allocated buffer whi
| 115 | * and return NULL instead of returning garbage data. |
| 116 | */ |
| 117 | static void *get_data(unsigned long size) |
| 118 | { |
| 119 | git_zstream stream; |
| 120 | unsigned long bufsize = dry_run && size > 8192 ? 8192 : size; |
| 121 | void *buf = xmallocz(bufsize); |
| 122 | |
| 123 | memset(&stream, 0, sizeof(stream)); |
| 124 | |
| 125 | stream.next_out = buf; |
| 126 | stream.avail_out = bufsize; |
| 127 | stream.next_in = fill(1); |
| 128 | stream.avail_in = len; |
| 129 | git_inflate_init(&stream); |
| 130 | |
| 131 | for (;;) { |
| 132 | int ret = git_inflate(&stream, 0); |
| 133 | use(len - stream.avail_in); |
| 134 | if (stream.total_out == size && ret == Z_STREAM_END) |
| 135 | break; |
| 136 | if (ret != Z_OK) { |
| 137 | error("inflate returned %d", ret); |
| 138 | FREE_AND_NULL(buf); |
| 139 | if (!recover) |
| 140 | exit(1); |
| 141 | has_errors = 1; |
| 142 | break; |
| 143 | } |
| 144 | stream.next_in = fill(1); |
| 145 | stream.avail_in = len; |
| 146 | if (dry_run) { |
| 147 | /* reuse the buffer in dry_run mode */ |
| 148 | stream.next_out = buf; |
| 149 | stream.avail_out = bufsize > size - stream.total_out ? |
| 150 | size - stream.total_out : |
| 151 | bufsize; |
| 152 | } |
| 153 | } |
| 154 | git_inflate_end(&stream); |
| 155 | if (dry_run) |
| 156 | FREE_AND_NULL(buf); |
| 157 | return buf; |
| 158 | } |
| 159 | |
| 160 | struct delta_info { |
| 161 | struct object_id base_oid; |
no test coverage detected