From: Stefan Sperling Subject: Re: got: rm * removes current directory To: Omar Polo , Mark Jamsek , Mikhail , gameoftrees@openbsd.org Date: Mon, 29 May 2023 18:27:00 +0200 On Mon, May 29, 2023 at 04:56:25PM +0200, Stefan Sperling wrote: > Like this? Omar pointed out off-list that in this diff I made the mistake of assigning -1 to a size_t (which is unsigned). So I would prefer to keep this code as-is to avoid falling into such traps. > diff /home/stsp/src/got > commit - 83769d30329a2744571b359ad7c849db5249ca79 > path + /home/stsp/src/got > blob - 9d45bcc89fba03349491b41c260b4fc0c9606531 > file + lib/worktree.c > --- lib/worktree.c > +++ lib/worktree.c > @@ -4477,15 +4477,17 @@ got_worktree_schedule_delete(struct got_worktree *work > > TAILQ_FOREACH(pe, paths, entry) { > char *ondisk_status_path; > + size_t len; > > - if (asprintf(&ondisk_status_path, "%s%s%s", > + len = asprintf(&ondisk_status_path, "%s%s%s", > got_worktree_get_root_path(worktree), > - pe->path[0] == '\0' ? "" : "/", pe->path) == -1) { > + pe->path[0] == '\0' ? "" : "/", pe->path); > + if (len == -1) { > err = got_error_from_errno("asprintf"); > goto done; > } > sda.status_path = ondisk_status_path; > - sda.status_path_len = strlen(ondisk_status_path); > + sda.status_path_len = len; > err = worktree_status(worktree, pe->path, fileindex, repo, > schedule_for_deletion, &sda, NULL, NULL, 1, 1); > free(ondisk_status_path);