Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
double output_alloc on ENOSPC
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Dec 21, 2017
1 parent d1c27a6 commit e95586e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions xdelta3/_xdelta3.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
output_buf, &output_size, output_alloc, flags);
} else {
// output shouldn't be bigger than the original plus the delta, but give a little leeway
output_alloc = input_size + source_size * 2;
output_buf = main_malloc(output_alloc);
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
output_buf, &output_size, output_alloc, flags);
output_alloc = input_size + source_size;
result = ENOSPC;
while (result == ENOSPC) {
output_buf = main_malloc(output_alloc);
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
output_buf, &output_size, output_alloc, flags);
output_alloc = output_alloc * 2;
}
}

if (result == 0) {
Expand All @@ -40,12 +44,8 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
}

if(result == ENOSPC) {
if (action == 0) {
// all is well, just not efficient delta could be found
PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value");
} else {
PyErr_SetString(XDeltaError, "Output of decoding delta longer than expected");
}
// all is well, just not efficient delta could be found
PyErr_SetString(NoDeltaFound, "No delta found shorter than the input value");
} else {
char exc_str[80];
sprintf(exc_str, "Error occur executing xdelta3: %s", xd3_strerror(result));
Expand Down

0 comments on commit e95586e

Please sign in to comment.