"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: two small fixes for got patch
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 11 Mar 2022 18:13:43 +0100

Download raw body.

Thread
On Fri, Mar 11, 2022 at 05:14:42PM +0100, Omar Polo wrote:
> Hello,
> 
> these are two unrelated tweaks but small enought that I'm sending them
> together.
> 
> The first one re-adds a lost lseek in patch_from_stdin.  That function
> copies the patch given on standard input to a temp file; during the
> refactoring before the addition of `got patch' i lost the lseek call.
> Without it, `got patch < diff' always fails with "no patch found".
> (while here also actually return the error...)
> 
> The second one is just a tweak: there's no need to call ftello after
> locate_hunk because it already knows the current position and can just
> return that to the caller.
> 
> OK?

Yes, makese sen. An additional suggestion below: 

> diff refs/remotes/origin/main refs/heads/main
> blob - 175740d9c6f4b9443624418107f8b2314f6f44b0
> blob + 7a5b68602669bd5b67c37c03000ec4c0e5e8568f
> --- got/got.c
> +++ got/got.c
> @@ -7150,9 +7150,12 @@ patch_from_stdin(int *patchfd)
>  	signal(SIGINT, sigint);
>  	signal(SIGQUIT, sigquit);
>  
> +	if (err == NULL && lseek(*patchfd, 0, SEEK_SET) == -1)
> +		err = got_error_from_errno("lseek");
> +
>  	if (err != NULL)
>  		close(*patchfd);

This should set *patchfd to -1 after closing the file to avoid
use of a closed file descriptor by the caller.

> -	return NULL;
> +	return err;
>  }