commit - 68bdcdc2f5d3c37d918f85368c2537a8aa7d90eb
commit + 0d15f6dcf929ae42606d3ca046621aee79e45890
blob - 45add0094489e3d46e675165b1d5379f56a01a4a
blob + c6481fe4c01d6cc1e445a9f0f588ec77b8003d3f
--- lib/deltify.c
+++ lib/deltify.c
const struct got_error *err = NULL;
int i;
uint8_t buf[GOT_DELTIFY_MAXCHUNK];
+ uint8_t buf2[GOT_DELTIFY_MAXCHUNK];
size_t r = 0;
if (len == 0)
i = h % dt->nalloc;
while (dt->blocks[i].len != 0) {
- if (r == 0) {
- if (fseeko(f, offset, SEEK_SET) == -1)
- return got_error_from_errno("fseeko");
- r = fread(buf, 1, len, f);
- if (r != len) {
- if (ferror(f))
- return got_ferror(f, GOT_ERR_IO);
- return NULL;
- }
- }
/*
* Avoid adding duplicate blocks.
* NB: A matching hash is insufficient for detecting equality.
* The hash can only detect inequality.
*/
if (len == dt->blocks[i].len && h == dt->blocks[i].hash) {
- uint8_t buf2[GOT_DELTIFY_MAXCHUNK];
+ if (r == 0) {
+ if (fseeko(f, offset, SEEK_SET) == -1)
+ return got_error_from_errno("fseeko");
+ r = fread(buf, 1, len, f);
+ if (r != len) {
+ if (!ferror(f))
+ return NULL;
+ return got_ferror(f, GOT_ERR_IO);
+ }
+ }
if (fseeko(f, dt->blocks[i].offset, SEEK_SET) == -1)
return got_error_from_errno("fseeko");
if (fread(buf2, 1, len, f) != len)