int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) { int error; git_signature *p = NULL; assert(name && email); *sig_out = NULL; p = git__calloc(1, sizeof(git_signature)); GITERR_CHECK_ALLOC(p); if ((error = process_trimming(name, &p->name, name + strlen(name), 1)) < 0 || (error = process_trimming(email, &p->email, email + strlen(email), 1)) < 0) { git_signature_free(p); return error; } p->when.time = time; p->when.offset = offset; *sig_out = p; return 0; }
int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) { git_signature *p = NULL; assert(name && email); *sig_out = NULL; p = git__calloc(1, sizeof(git_signature)); GITERR_CHECK_ALLOC(p); if (process_trimming(name, &p->name, name + strlen(name), 1) < 0 || process_trimming(email, &p->email, email + strlen(email), 1) < 0) { git_signature_free(p); return -1; } if (contains_angle_brackets(p->email) || contains_angle_brackets(p->name)) { git_signature_free(p); return signature_error("Neither `name` nor `email` should contain angle brackets chars."); } p->when.time = time; p->when.offset = offset; *sig_out = p; return 0; }
int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) { int error; git_signature *p = NULL; assert(name && email); *sig_out = NULL; if ((p = git__malloc(sizeof(git_signature))) == NULL) { error = GIT_ENOMEM; goto cleanup; } memset(p, 0x0, sizeof(git_signature)); error = process_trimming(name, &p->name, name + strlen(name), 1); if (error < GIT_SUCCESS) { git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'name' argument is invalid"); goto cleanup; } error = process_trimming(email, &p->email, email + strlen(email), 1); if (error < GIT_SUCCESS) { git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'email' argument is invalid"); goto cleanup; } p->when.time = time; p->when.offset = offset; *sig_out = p; return error; cleanup: git_signature_free(p); return error; }