| 1 |
|
| /* |
| 2 |
|
| * Copyright (C) the libgit2 contributors. All rights reserved. |
| 3 |
|
| * |
| 4 |
|
| * This file is part of libgit2, distributed under the GNU GPL v2 with |
| 5 |
|
| * a Linking Exception. For full terms see the included COPYING file. |
| 6 |
|
| */ |
| 7 |
|
| |
| 8 |
|
| #include "util.h" |
| 9 |
|
| |
| 10 |
|
| #include "common.h" |
| 11 |
|
| |
| 12 |
4 |
| int git_strarray_copy(git_strarray *tgt, const git_strarray *src) |
| 13 |
|
| { |
| 14 |
|
| size_t i; |
| 15 |
|
| |
| 16 |
4 |
▶ | GIT_ASSERT_ARG(tgt); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(tgt); |
0 |
4 |
4 |
|
| 17 |
4 |
▶ | GIT_ASSERT_ARG(src); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(src); |
0 |
4 |
4 |
|
| 18 |
|
| |
| 19 |
4 |
| memset(tgt, 0, sizeof(*tgt)); |
| 20 |
|
| |
| 21 |
4 |
▶ | if (!src->count) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!src->count) |
4 |
0 |
4 |
|
| 22 |
4 |
| return 0; |
| 23 |
|
| |
| 24 |
0 |
| tgt->strings = git__calloc(src->count, sizeof(char *)); |
| 25 |
0 |
▶ | GIT_ERROR_CHECK_ALLOC(tgt->strings); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC(tgt->strings); |
0 |
0 |
0 |
|
| 26 |
|
| |
| 27 |
0 |
▶ | for (i = 0; i < src->count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < src->count; ++i) { |
0 |
0 |
0 |
|
| 28 |
0 |
▶ | if (!src->strings[i]) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!src->strings[i]) |
0 |
0 |
0 |
|
| 29 |
0 |
| continue; |
| 30 |
|
| |
| 31 |
0 |
| tgt->strings[tgt->count] = git__strdup(src->strings[i]); |
| 32 |
0 |
▶ | if (!tgt->strings[tgt->count]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tgt->strings[tgt->count]) { |
0 |
0 |
0 |
|
| 33 |
0 |
| git_strarray_dispose(tgt); |
| 34 |
0 |
| memset(tgt, 0, sizeof(*tgt)); |
| 35 |
0 |
| return -1; |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
0 |
| tgt->count++; |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
0 |
| return 0; |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
36 |
| void git_strarray_dispose(git_strarray *array) |
| 45 |
|
| { |
| 46 |
|
| size_t i; |
| 47 |
|
| |
| 48 |
36 |
▶ | if (array == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (array == NULL) |
0 |
36 |
36 |
|
| 49 |
0 |
| return; |
| 50 |
|
| |
| 51 |
49 |
▶ | for (i = 0; i < array->count; ++i) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < array->count; ++i) |
13 |
36 |
49 |
|
| 52 |
13 |
| git__free(array->strings[i]); |
| 53 |
|
| |
| 54 |
36 |
| git__free(array->strings); |
| 55 |
|
| |
| 56 |
36 |
| memset(array, 0, sizeof(*array)); |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
|
| #ifndef GIT_DEPRECATE_HARD |
| 60 |
6 |
| void git_strarray_free(git_strarray *array) |
| 61 |
|
| { |
| 62 |
6 |
| git_strarray_dispose(array); |
| 63 |
6 |
| } |
| 64 |
|
| #endif |