commit 0a585a0d6446ac47834148d4071c8374ffc15bc2 from: Stefan Sperling date: Sat Mar 17 17:13:19 2018 UTC remove GOT_ERR_NO_MEM, we can just use errno in those cases commit - 718b3ab0e353c4ccb510b0ec9c3673b1c9a7344e commit + 0a585a0d6446ac47834148d4071c8374ffc15bc2 blob - 176c6094f97ba96eef191fd7cce0f0fb50a415f8 blob + 40c422e336c4d5c0b4b5787d84c0659f5b64eb5b --- got/got.c +++ got/got.c @@ -190,15 +190,16 @@ cmd_checkout(int argc, char *argv[]) if (dotgit) *dotgit = '\0'; if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) { + error = got_error_from_errno(); free(cwd); - return got_error(GOT_ERR_NO_MEM); + return error; } free(cwd); } else if (argc == 2) { repo_path = argv[0]; worktree_path = strdup(argv[1]); if (worktree_path == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); } else usage_checkout(); @@ -272,11 +273,12 @@ print_commits(struct got_object *root_obj, struct got_ entry = calloc(1, sizeof(*entry)); if (entry == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); entry->id = got_object_id_dup(root_id); if (entry->id == NULL) { + err = got_error_from_errno(); free(entry); - return got_error(GOT_ERR_NO_MEM); + return err; } entry->commit = root_commit; TAILQ_INSERT_HEAD(&commits, entry, entry); @@ -309,13 +311,13 @@ print_commits(struct got_object *root_obj, struct got_ pentry = calloc(1, sizeof(*pentry)); if (pentry == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); got_object_commit_close(pcommit); break; } pentry->id = got_object_id_dup(pid->id); if (pentry->id == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); got_object_commit_close(pcommit); break; } blob - 0d03e126ff7964bff61f602b55e570eb2f97f80e blob + ad4669b8af10e9550be1ac1e704c3103fe2a4717 --- include/got_error.h +++ include/got_error.h @@ -15,8 +15,8 @@ */ /* Error codes */ -#define GOT_ERR_ERRNO 0 -#define GOT_ERR_NO_MEM 1 +#define GOT_ERR_OK 0 +#define GOT_ERR_ERRNO 1 #define GOT_ERR_NOT_GIT_REPO 2 #define GOT_ERR_NOT_ABSPATH 3 #define GOT_ERR_BAD_PATH 4 @@ -50,8 +50,8 @@ static const struct got_error { int code; const char *msg; } got_errors[] = { + { GOT_ERR_OK, "no error occured?!?" }, { GOT_ERR_ERRNO, "see errno" }, - { GOT_ERR_NO_MEM, "out of memory" }, { GOT_ERR_NOT_GIT_REPO, "no git repository found" }, { GOT_ERR_NOT_ABSPATH, "absolute path expected" }, { GOT_ERR_BAD_PATH, "bad path" }, blob - 2fdd381ceed1dd1ccdb46640879c87952edbd56e blob + c20c1b37c4bb7b60227b956fd033fecaa0c99a90 --- lib/diffreg.c +++ lib/diffreg.c @@ -331,11 +331,11 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags, goto closem; } if (prepare(ds, 0, f1, ds->stb1.st_size, flags)) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } if (prepare(ds, 1, f2, ds->stb2.st_size, flags)) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } @@ -347,44 +347,46 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags, equiv(ds->sfile[0], ds->slen[0], ds->sfile[1], ds->slen[1], ds->member); ds->member = reallocarray(ds->member, ds->slen[1] + 2, sizeof(*ds->member)); if (ds->member == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } ds->class = (int *)ds->file[0]; if (unsort(ds->sfile[0], ds->slen[0], ds->class)) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } ds->class = reallocarray(ds->class, ds->slen[0] + 2, sizeof(*ds->class)); if (ds->class == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } ds->klist = calloc(ds->slen[0] + 2, sizeof(*ds->klist)); if (ds->klist == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } ds->clen = 0; ds->clistlen = 100; ds->clist = calloc(ds->clistlen, sizeof(*ds->clist)); if (ds->clist == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } i = stone(ds, ds->class, ds->slen[0], ds->member, ds->klist, flags); - free(ds->member); - free(ds->class); - if (i < 0) { - err = got_error(GOT_ERR_NO_MEM); + if (i < 0) { + err = got_error_from_errno(); + free(ds->member); + free(ds->class); goto closem; } + free(ds->member); + free(ds->class); ds->J = reallocarray(ds->J, ds->len[0] + 2, sizeof(*ds->J)); if (ds->J == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } unravel(ds, ds->klist[i]); @@ -395,18 +397,18 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags, ds->ixold = reallocarray(ds->ixold, ds->len[0] + 2, sizeof(*ds->ixold)); if (ds->ixold == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } ds->ixnew = reallocarray(ds->ixnew, ds->len[1] + 2, sizeof(*ds->ixnew)); if (ds->ixnew == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto closem; } check(ds, f1, f2, flags); if (output(outfile, ds, args, args->label[0], f1, args->label[1], f2, flags)) - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); closem: if (ds->anychange) { args->status |= 1; blob - 6c2d120fdfd7717d4ea98634d7730201bdf56fd3 blob + 6511dec1ab084d3e840d1133d5f07de1af53674e --- lib/fileindex.c +++ lib/fileindex.c @@ -39,13 +39,14 @@ got_fileindex_entry_open(struct got_fileindex_entry ** *entry = calloc(1, sizeof(**entry)); if (*entry == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*entry)->path = strdup(relpath); if ((*entry)->path == NULL) { + const struct got_error *err = got_error_from_errno(); free(*entry); *entry = NULL; - return got_error(GOT_ERR_NO_MEM); + return err; } (*entry)->ctime_sec = sb.st_ctime; blob - 7037325a47c164cee43c0303029705ceb1a19f7a blob + 7f38f5a672366753baf1915c00cc6a8d37a515e4 --- lib/object.c +++ lib/object.c @@ -60,7 +60,7 @@ got_object_id_str(char **outbuf, struct got_object_id *outbuf = calloc(1, len); if (*outbuf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) { free(*outbuf); @@ -152,7 +152,7 @@ parse_object_header(struct got_object **obj, char *buf *obj = calloc(1, sizeof(**obj)); if (*obj == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*obj)->type = type; (*obj)->hdrlen = hdrlen; (*obj)->size = size; @@ -172,7 +172,7 @@ read_object_header(struct got_object **obj, struct got buf = calloc(zbsize, sizeof(char)); if (buf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); err = got_inflate_init(&zb, NULL, zbsize); if (err) @@ -187,7 +187,7 @@ read_object_header(struct got_object **obj, struct got if (strchr(zb.outbuf, '\0') == NULL) { buf = recallocarray(buf, 1 + i, 2 + i, zbsize); if (buf == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } } @@ -210,7 +210,7 @@ object_path(char **path, struct got_object_id *id, str char *path_objects = got_repo_get_path_objects(repo); if (path_objects == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); err = got_object_id_str(&hex, id); if (err) @@ -218,7 +218,7 @@ object_path(char **path, struct got_object_id *id, str if (asprintf(path, "%s/%.2x/%s", path_objects, id->sha1[0], hex + 2) == -1) - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); free(hex); free(path_objects); @@ -319,12 +319,13 @@ parse_commit_object(struct got_commit_object **commit, *commit = calloc(1, sizeof(**commit)); if (*commit == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*commit)->tree_id = calloc(1, sizeof(*(*commit)->tree_id)); if ((*commit)->tree_id == NULL) { + err = got_error_from_errno(); free(*commit); *commit = NULL; - return got_error(GOT_ERR_NO_MEM); + return err; } SIMPLEQ_INIT(&(*commit)->parent_ids); @@ -360,13 +361,13 @@ parse_commit_object(struct got_commit_object **commit, pid = calloc(1, sizeof(*pid)); if (pid == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } pid->id = calloc(1, sizeof(*pid->id)); if (pid->id == NULL) { + err = got_error_from_errno(); free(pid); - err = got_error(GOT_ERR_NO_MEM); goto done; } s += tlen; @@ -401,7 +402,7 @@ parse_commit_object(struct got_commit_object **commit, *p = '\0'; (*commit)->author = strdup(s); if ((*commit)->author == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } s += strlen((*commit)->author) + 1; @@ -426,7 +427,7 @@ parse_commit_object(struct got_commit_object **commit, *p = '\0'; (*commit)->committer = strdup(s); if ((*commit)->committer == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } s += strlen((*commit)->committer) + 1; @@ -435,7 +436,7 @@ parse_commit_object(struct got_commit_object **commit, (*commit)->logmsg = strndup(s, remain); if ((*commit)->logmsg == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } done: @@ -463,13 +464,14 @@ parse_tree_entry(struct got_tree_entry **te, size_t *e *te = calloc(1, sizeof(**te)); if (*te == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*te)->id = calloc(1, sizeof(*(*te)->id)); if ((*te)->id == NULL) { + err = got_error_from_errno(); free(*te); *te = NULL; - return got_error(GOT_ERR_NO_MEM); + return err; } *elen = strlen(buf) + 1; @@ -481,9 +483,10 @@ parse_tree_entry(struct got_tree_entry **te, size_t *e space = strchr(buf, ' '); if (space == NULL) { + err = got_error(GOT_ERR_BAD_OBJ_DATA); free(*te); *te = NULL; - return got_error(GOT_ERR_BAD_OBJ_DATA); + return err; } while (*p != ' ') { if (*p < '0' && *p > '7') { @@ -520,7 +523,7 @@ parse_tree_object(struct got_tree_object **tree, struc *tree = calloc(1, sizeof(**tree)); if (*tree == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); SIMPLEQ_INIT(&(*tree)->entries); @@ -558,7 +561,7 @@ read_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f) buf = calloc(1, blocksize); if (buf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); remain = blocksize; total = 0; @@ -567,7 +570,7 @@ read_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f) uint8_t *newbuf; newbuf = reallocarray(buf, 1, total + blocksize); if (newbuf == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } buf = newbuf; @@ -755,14 +758,15 @@ got_object_blob_open(struct got_blob_object **blob, *blob = calloc(1, sizeof(**blob)); if (*blob == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); if (obj->flags & GOT_OBJ_FLAG_PACKED) { (*blob)->read_buf = calloc(1, blocksize); if ((*blob)->read_buf == NULL) { + err = got_error_from_errno(); free(*blob); *blob = NULL; - return got_error(GOT_ERR_NO_MEM); + return err; } err = got_packfile_extract_object(&((*blob)->f), obj, repo); if (err) { blob - 13400cde614412fa2c8db10001786781d672f8d8 blob + f9c3ce7964f9b871111c17a917f1e3348cae9ea3 --- lib/pack.c +++ lib/pack.c @@ -89,7 +89,7 @@ get_packfile_size(size_t *size, const char *path_idx) return got_error(GOT_ERR_BAD_PATH); *dot = '\0'; if (asprintf(&path_pack, "%s.pack", base_path) == -1) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); if (stat(path_pack, &sb) != 0) { free(path_pack); @@ -123,7 +123,7 @@ got_packidx_open(struct got_packidx_v2_hdr **packidx, p = calloc(1, sizeof(*p)); if (p == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -169,7 +169,7 @@ got_packidx_open(struct got_packidx_v2_hdr **packidx, p->sorted_ids = calloc(nobj, sizeof(*p->sorted_ids)); if (p->sorted_ids == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -184,7 +184,7 @@ got_packidx_open(struct got_packidx_v2_hdr **packidx, p->crc32 = calloc(nobj, sizeof(*p->crc32)); if (p->crc32 == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -198,7 +198,7 @@ got_packidx_open(struct got_packidx_v2_hdr **packidx, p->offsets = calloc(nobj, sizeof(*p->offsets)); if (p->offsets == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -216,7 +216,7 @@ got_packidx_open(struct got_packidx_v2_hdr **packidx, p->large_offsets = calloc(nobj, sizeof(*p->large_offsets)); if (p->large_offsets == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -404,8 +404,6 @@ search_packidx(struct got_packidx_v2_hdr **packidx, in *idx = get_object_idx(repo->packidx_cache[i], id); if (*idx != -1) { *packidx = repo->packidx_cache[i]; - if (*packidx == NULL) - return got_error(GOT_ERR_NO_MEM); return NULL; } } @@ -413,7 +411,7 @@ search_packidx(struct got_packidx_v2_hdr **packidx, in path_packdir = got_repo_get_path_objects_pack(repo); if (path_packdir == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); packdir = opendir(path_packdir); if (packdir == NULL) { @@ -427,7 +425,7 @@ search_packidx(struct got_packidx_v2_hdr **packidx, in if (asprintf(&path_packidx, "%s/%s", path_packdir, dent->d_name) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -465,7 +463,7 @@ get_packfile_path(char **path_packfile, struct got_rep path_packdir = got_repo_get_path_objects_pack(repo); if (path_packdir == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); sha1str = got_sha1_digest_to_str(packidx->trailer.packfile_sha1, hex, sizeof(hex)); @@ -475,7 +473,7 @@ get_packfile_path(char **path_packfile, struct got_rep if (asprintf(path_packfile, "%s/%s%s%s", path_packdir, GOT_PACK_PREFIX, sha1str, GOT_PACKFILE_SUFFIX) == -1) { *path_packfile = NULL; - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); } return NULL; @@ -565,7 +563,7 @@ cache_pack(struct got_pack **packp, const char *path_p pack->path_packfile = strdup(path_packfile); if (pack->path_packfile == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -643,13 +641,14 @@ open_plain_object(struct got_object **obj, const char { *obj = calloc(1, sizeof(**obj)); if (*obj == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*obj)->path_packfile = strdup(path_packfile); if ((*obj)->path_packfile == NULL) { + const struct got_error *err = got_error_from_errno(); free(*obj); *obj = NULL; - return got_error(GOT_ERR_NO_MEM); + return err; } (*obj)->type = type; @@ -728,7 +727,7 @@ add_delta(struct got_delta_chain *deltas, const char * delta_type, delta_size, delta_data_offset, delta_buf, delta_len); if (delta == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); /* delta is freed in got_object_close() */ deltas->nentries++; SIMPLEQ_INSERT_HEAD(&deltas->entries, delta, entry); @@ -899,7 +898,7 @@ open_delta_object(struct got_object **obj, struct got_ *obj = calloc(1, sizeof(**obj)); if (*obj == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*obj)->flags = 0; (*obj)->hdrlen = 0; @@ -909,7 +908,7 @@ open_delta_object(struct got_object **obj, struct got_ (*obj)->path_packfile = strdup(path_packfile); if ((*obj)->path_packfile == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } (*obj)->flags |= GOT_OBJ_FLAG_PACKED; @@ -1070,7 +1069,7 @@ dump_delta_chain_to_file(size_t *result_size, struct g if (max_size < GOT_DELTA_RESULT_SIZE_CACHED_MAX) { accum_buf = malloc(max_size); if (accum_buf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); } else { base_file = got_opentemp(); if (base_file == NULL) @@ -1113,7 +1112,7 @@ dump_delta_chain_to_file(size_t *result_size, struct g uint8_t *p; p = reallocarray(base_buf, 1, max_size); if (p == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } base_buf = p; @@ -1198,7 +1197,7 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outl return err; accum_buf = malloc(max_size); if (accum_buf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); /* Deltas are ordered in ascending order. */ SIMPLEQ_FOREACH(delta, &deltas->entries, entry) { @@ -1225,7 +1224,7 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outl uint8_t *p; p = reallocarray(base_buf, 1, max_size); if (p == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } base_buf = p; blob - ddd0a1e67d31a851c76efbed97aea073100c7c67 blob + 8f96a5ac2f50abfaf71dbecfc5616812983db43a --- lib/path.c +++ lib/path.c @@ -71,7 +71,7 @@ got_path_segment_count(int *count, const char *path) *count = 0; if (s == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); do { p = strsep(&s, "/"); @@ -114,7 +114,7 @@ got_opentemp_named(char **path, FILE **outfile, const if (asprintf(path, "%s-XXXXXX", basepath) == -1) { *path = NULL; - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); } fd = mkstemp(*path); blob - 07d6b874c947c74d3665545cea5b355672bb3220 blob + fd179690cf9795fbf834b926133053006ed3847d --- lib/refs.c +++ lib/refs.c @@ -70,16 +70,17 @@ parse_symref(struct got_reference **ref, const char *n symref_name = strdup(name); if (symref_name == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); symref_ref = strdup(line); if (symref_ref == NULL) { + const struct got_error *err = got_error_from_errno(); free(symref_name); - return got_error(GOT_ERR_NO_MEM); + return err; } *ref = calloc(1, sizeof(**ref)); if (*ref == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*ref)->flags |= GOT_REF_IS_SYMBOLIC; symref = &((*ref)->ref.symref); symref->name = symref_name; @@ -100,14 +101,14 @@ parse_ref_line(struct got_reference **ref, const char ref_name = strdup(name); if (ref_name == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); if (!got_parse_sha1_digest(digest, line)) return got_error(GOT_ERR_NOT_REF); *ref = calloc(1, sizeof(**ref)); if (*ref == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); (*ref)->ref.ref.name = ref_name; memcpy(&(*ref)->ref.ref.sha1, digest, SHA1_DIGEST_LENGTH); return NULL; @@ -162,14 +163,14 @@ got_ref_open(struct got_reference **ref, struct got_re char *path_refs = get_refs_dir_path(repo, refname); if (path_refs == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } /* XXX For now, this assumes that refs exist in the filesystem. */ if (asprintf(&path_ref, "%s/%s", path_refs, refname) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -269,7 +270,7 @@ got_ref_resolve(struct got_object_id **id, struct got_ *id = calloc(1, sizeof(**id)); if (*id == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); memcpy((*id)->sha1, ref->ref.ref.sha1, SHA1_DIGEST_LENGTH); return NULL; } blob - 9dea7fe71449e02beed91b0051eb9da34de1a42e blob + 086900f78bedad14dd2f6881c2e8949f43b8a9cc --- lib/repository.c +++ lib/repository.c @@ -161,7 +161,7 @@ got_repo_open(struct got_repository **ret, const char repo = calloc(1, sizeof(*repo)); if (repo == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -173,14 +173,14 @@ got_repo_open(struct got_repository **ret, const char repo->path_git_dir = strdup(repo->path); if (repo->path_git_dir == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } if (!is_git_repo(repo)) { free(repo->path_git_dir); if (asprintf(&repo->path_git_dir, "%s/%s", repo->path, GOT_GIT_DIR) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } if (!is_git_repo(repo)) { blob - 63c5da80f96650880e5a9b02c0efadd40d22d9c3 blob + 80b9f971f82e444c5e97fda10624390229449f99 --- lib/worktree.c +++ lib/worktree.c @@ -56,7 +56,7 @@ create_meta_file(const char *path_got, const char *nam ssize_t n; if (asprintf(&path, "%s/%s", path_got, name) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); path = NULL; goto done; } @@ -103,7 +103,7 @@ read_meta_file(char **content, const char *path_got, c *content = NULL; if (asprintf(&path, "%s/%s", path_got, name) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); path = NULL; goto done; } @@ -122,7 +122,7 @@ read_meta_file(char **content, const char *path_got, c stat(path, &sb); *content = calloc(1, sb.st_size); if (*content == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } @@ -162,7 +162,7 @@ got_worktree_init(const char *path, struct got_referen if (!got_path_is_absolute(prefix)) { if (asprintf(&absprefix, "/%s", prefix) == -1) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); } /* Create top-level directory (may already exist). */ @@ -173,7 +173,7 @@ got_worktree_init(const char *path, struct got_referen /* Create .got directory (may already exist). */ if (asprintf(&path_got, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } if (mkdir(path_got, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST) { @@ -194,7 +194,7 @@ got_worktree_init(const char *path, struct got_referen /* Write the HEAD reference. */ refstr = got_ref_to_str(head_ref); if (refstr == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } err = create_meta_file(path_got, GOT_WORKTREE_HEAD, refstr); @@ -204,7 +204,7 @@ got_worktree_init(const char *path, struct got_referen /* Store path to repository. */ repo_path = got_repo_get_path(repo); if (repo_path == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } err = create_meta_file(path_got, GOT_WORKTREE_REPOSITORY, repo_path); @@ -219,7 +219,7 @@ got_worktree_init(const char *path, struct got_referen /* Stamp work tree with format file. */ if (asprintf(&formatstr, "%d", GOT_WORKTREE_FORMAT_VERSION) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } err = create_meta_file(path_got, GOT_WORKTREE_FORMAT, formatstr); @@ -248,13 +248,13 @@ got_worktree_open(struct got_worktree **worktree, cons *worktree = NULL; if (asprintf(&path_got, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); path_got = NULL; goto done; } if (asprintf(&path_lock, "%s/%s", path_got, GOT_WORKTREE_LOCK) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); path_lock = NULL; goto done; } @@ -282,14 +282,14 @@ got_worktree_open(struct got_worktree **worktree, cons *worktree = calloc(1, sizeof(**worktree)); if (*worktree == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } (*worktree)->lockfd = -1; (*worktree)->root_path = strdup(path); if ((*worktree)->root_path == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } err = read_meta_file(&(*worktree)->repo_path, path_got, @@ -377,7 +377,7 @@ add_file_on_disk(struct got_worktree *worktree, struct if (asprintf(&ondisk_path, "%s/%s", worktree->root_path, apply_path_prefix(worktree, path)) == -1) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); fd = open(ondisk_path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE); @@ -439,7 +439,7 @@ add_dir_on_disk(struct got_worktree *worktree, const c if (asprintf(&abspath, "%s/%s", worktree->root_path, apply_path_prefix(worktree, path)) == -1) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); /* XXX queue work rather than editing disk directly? */ if (mkdir(abspath, GOT_DEFAULT_DIR_MODE) == -1) { @@ -487,7 +487,7 @@ tree_checkout_entry(struct got_worktree *worktree, if (parent[0] == '/' && parent[1] == '\0') parent = ""; if (asprintf(&path, "%s/%s", parent, te->name) == -1) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); /* Skip this entry if it is outside of our path prefix. */ len = MIN(strlen(worktree->path_prefix), strlen(path)); @@ -583,13 +583,13 @@ got_worktree_checkout_files(struct got_worktree *workt fileindex = got_fileindex_open(); if (fileindex == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path, GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); fileindex_path = NULL; goto done; } blob - 9024264945ebfbe8bb734400daa2cc59cb0f4b2a blob + 93279f0bf680a472e0cb41a40a8d532c98c55778 --- lib/zbuf.c +++ lib/zbuf.c @@ -46,14 +46,14 @@ got_inflate_init(struct got_zstream_buf *zb, uint8_t * zb->inbuf = calloc(1, zb->inlen); if (zb->inbuf == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } if (outbuf == NULL) { zb->outbuf = calloc(1, zb->outlen); if (zb->outbuf == NULL) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); goto done; } zb->flags |= GOT_ZSTREAM_F_OWN_OUTBUF; @@ -122,7 +122,7 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, F *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE); if (*outbuf == NULL) - return got_error(GOT_ERR_NO_MEM); + return got_error_from_errno(); err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE); if (err) return err; @@ -138,10 +138,10 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, F newbuf = reallocarray(*outbuf, 1, *outlen + GOT_ZSTREAM_BUFSIZE); if (newbuf == NULL) { + err = got_error_from_errno(); free(*outbuf); *outbuf = NULL; *outlen = 0; - err = got_error(GOT_ERR_NO_MEM); goto done; } *outbuf = newbuf; blob - 6f6b30cdc1b2834f1e57dff4822ac9c4b05dd250 blob + d822baa5771cc1ed7cc4de41a1385a96bf47e34e --- regress/repository/repository_test.c +++ regress/repository/repository_test.c @@ -112,7 +112,7 @@ print_tree_object(struct got_object *obj, char *parent } if (asprintf(&next_parent, "%s/%s", parent, te->name) == -1) { - err = got_error(GOT_ERR_NO_MEM); + err = got_error_from_errno(); got_object_close(treeobj); break; }