Re: [PATCH] src/ext4_resize.c: set errno to 0 before the strtoull call

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Mon, Jan 17, 2022 at 03:36:54PM +0800, Yang Xu wrote:
> On my test machine, ext4/033 fails even use the non-overflow size.
> It reports invalid new size when using strtoull because errno is 1.
> 
> As man-pages said "Since  strtoul()  can legitimately return 0 or ULONG_MAX
> (ULLONG_MAX for strtoull()) on both success and failure, the calling program
> should set errno to 0 before the call, and then determine if an error occurred
> by checking whether errno has a nonzero value after the call".
> 
> So add a step to set errno to 0 before strtoull call.
> 
> Fixes: 92b9c0dedace ("ext4/033: test EXT4_IOC_RESIZE_FS by calling the ioctl directly")
> Signed-off-by: Yang Xu <xuyang2018.jy@xxxxxxxxxxx>

Looks good,
Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx>

--D

> ---
>  src/ext4_resize.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/ext4_resize.c b/src/ext4_resize.c
> index 1ac51e6f..39e16529 100644
> --- a/src/ext4_resize.c
> +++ b/src/ext4_resize.c
> @@ -35,6 +35,7 @@ int main(int argc, char **argv)
>  		return 1;
>  	}
>  
> +	errno = 0;
>  	new_size = strtoull(argv[2], &tmp, 10);
>  	if ((errno) || (*tmp != '\0')) {
>  		fprintf(stderr, "%s: invalid new size\n", argv[0]);
> -- 
> 2.23.0
> 



[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux