ext/rugged/vendor/libgit2-dist/src/delta-apply.c in rugged-0.16.0 vs ext/rugged/vendor/libgit2-dist/src/delta-apply.c in rugged-0.17.0b1

- old
+ new

@@ -1,7 +1,7 @@ /* - * Copyright (C) 2009-2011 the libgit2 contributors + * Copyright (C) 2009-2012 the libgit2 contributors * * This file is part of libgit2, distributed under the GNU GPL v2 with * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -49,18 +49,23 @@ /* Check that the base size matches the data we were given; * if not we would underflow while accessing data from the * base object, resulting in data corruption or segfault. */ - if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) - return git__throw(GIT_ERROR, "Failed to apply delta. Base size does not match given data"); + if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) { + giterr_set(GITERR_INVALID, "Failed to apply delta. Base size does not match given data"); + return -1; + } - if (hdr_sz(&res_sz, &delta, delta_end) < 0) - return git__throw(GIT_ERROR, "Failed to apply delta. Base size does not match given data"); + if (hdr_sz(&res_sz, &delta, delta_end) < 0) { + giterr_set(GITERR_INVALID, "Failed to apply delta. Base size does not match given data"); + return -1; + } - if ((res_dp = git__malloc(res_sz + 1)) == NULL) - return GIT_ENOMEM; + res_dp = git__malloc(res_sz + 1); + GITERR_CHECK_ALLOC(res_dp); + res_dp[res_sz] = '\0'; out->data = res_dp; out->len = res_sz; while (delta < delta_end) { @@ -104,12 +109,13 @@ } } if (delta != delta_end || res_sz) goto fail; - return GIT_SUCCESS; + return 0; fail: git__free(out->data); out->data = NULL; - return git__throw(GIT_ERROR, "Failed to apply delta"); + giterr_set(GITERR_INVALID, "Failed to apply delta"); + return -1; }