FreeBSD: Fix uninitialized variable error

On FreeBSD errno is defined as (* __error()), which means compiler
can't say whether two consecutive reads will return the same.
And without this knowledge the reported error is formally right.

Caching of the errno in local variable fixes the issue.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #17975
This commit is contained in:
Alexander Motin 2025-11-25 05:16:35 -05:00 committed by Brian Behlendorf
parent c8ecd63acd
commit 2e09f166f0

View File

@ -124,10 +124,12 @@ zfs_tunable_parse_int(const char *val, intmax_t *np,
{
intmax_t n;
char *end;
int err;
errno = 0;
n = strtoimax(val, &end, 0);
if (errno != 0)
return (errno);
if ((err = errno) != 0)
return (err);
if (*end != '\0')
return (EINVAL);
if (n < min || n > max)
@ -142,10 +144,12 @@ zfs_tunable_parse_uint(const char *val, uintmax_t *np,
{
uintmax_t n;
char *end;
int err;
errno = 0;
n = strtoumax(val, &end, 0);
if (errno != 0)
return (errno);
if ((err = errno) != 0)
return (err);
if (*end != '\0')
return (EINVAL);
if (strchr(val, '-'))