diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-02-12 12:19:37 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2015-02-13 09:27:33 -0500 |
| commit | f1453c59b2afb9dab43281bfe9f1ba34cf6e0d02 (patch) | |
| tree | cb189e211547042080f35227b7e4d3f9b0c8ac2a /src/diff_patch.c | |
| parent | 650e45f69124bd8b53ecefddeb214a82538ab2c1 (diff) | |
| download | libgit2-f1453c59b2afb9dab43281bfe9f1ba34cf6e0d02.tar.gz | |
Make our overflow check look more like gcc/clang's
Make our overflow checking look more like gcc and clang's, so that
we can substitute it out with the compiler instrinsics on platforms
that support it. This means dropping the ability to pass `NULL` as
an out parameter.
As a result, the macros also get updated to reflect this as well.
Diffstat (limited to 'src/diff_patch.c')
| -rw-r--r-- | src/diff_patch.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/diff_patch.c b/src/diff_patch.c index f5eecae66..1c4c0e8b8 100644 --- a/src/diff_patch.c +++ b/src/diff_patch.c @@ -388,16 +388,11 @@ static int diff_patch_with_delta_alloc( diff_patch_with_delta *pd; size_t old_len = *old_path ? strlen(*old_path) : 0; size_t new_len = *new_path ? strlen(*new_path) : 0; - size_t alloc_len = sizeof(*pd); + size_t alloc_len; - GITERR_CHECK_ALLOC_ADD(alloc_len, old_len); - alloc_len += old_len; - - GITERR_CHECK_ALLOC_ADD(alloc_len, new_len); - alloc_len += new_len; - - GITERR_CHECK_ALLOC_ADD(alloc_len, 2); - alloc_len += 2; + GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len); + GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len); + GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); *out = pd = git__calloc(1, alloc_len); GITERR_CHECK_ALLOC(pd); |
