diff options
author | Arthur Schreiber <schreiber.arthur@googlemail.com> | 2014-01-14 21:33:35 +0100 |
---|---|---|
committer | Arthur Schreiber <schreiber.arthur@googlemail.com> | 2014-01-14 21:33:35 +0100 |
commit | 29be3a6d9eee68b3964f34c498e64ce32452a57f (patch) | |
tree | 050d954faf76b31b6b42538116f28006bfeac7ef /src/signature.c | |
parent | 76c00ead59f710a8dfeb6464eafcb4d65e26a7db (diff) | |
download | libgit2-29be3a6d9eee68b3964f34c498e64ce32452a57f.tar.gz |
Align git_signature_dup.
This changes git_signature_dup to actually honor oom conditions raised by
the call to git__strdup. It also aligns it with the error code return
pattern used everywhere else.
Diffstat (limited to 'src/signature.c')
-rw-r--r-- | src/signature.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/signature.c b/src/signature.c index ec51a42e9..f658d6035 100644 --- a/src/signature.c +++ b/src/signature.c @@ -82,23 +82,28 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema return 0; } -git_signature *git_signature_dup(const git_signature *sig) +int git_signature_dup(git_signature **dest, const git_signature *source) { - git_signature *new; + git_signature *signature; - if (sig == NULL) - return NULL; + if (source == NULL) + return 0; + + signature = git__calloc(1, sizeof(git_signature)); + GITERR_CHECK_ALLOC(signature); + + signature->name = git__strdup(source->name); + GITERR_CHECK_ALLOC(signature->name); - new = git__calloc(1, sizeof(git_signature)); - if (new == NULL) - return NULL; + signature->email = git__strdup(source->email); + GITERR_CHECK_ALLOC(signature->email); - new->name = git__strdup(sig->name); - new->email = git__strdup(sig->email); - new->when.time = sig->when.time; - new->when.offset = sig->when.offset; + signature->when.time = source->when.time; + signature->when.offset = source->when.offset; - return new; + *dest = signature; + + return 0; } int git_signature_now(git_signature **sig_out, const char *name, const char *email) |