Skip to content

Commit 7f7d493

Browse files
authored
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 <[email protected]> Reviewed-by: Rob Norris <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes #17975
1 parent e37937f commit 7f7d493

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/libspl/tunables.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ zfs_tunable_parse_int(const char *val, intmax_t *np,
124124
{
125125
intmax_t n;
126126
char *end;
127+
int err;
128+
127129
errno = 0;
128130
n = strtoimax(val, &end, 0);
129-
if (errno != 0)
130-
return (errno);
131+
if ((err = errno) != 0)
132+
return (err);
131133
if (*end != '\0')
132134
return (EINVAL);
133135
if (n < min || n > max)
@@ -142,10 +144,12 @@ zfs_tunable_parse_uint(const char *val, uintmax_t *np,
142144
{
143145
uintmax_t n;
144146
char *end;
147+
int err;
148+
145149
errno = 0;
146150
n = strtoumax(val, &end, 0);
147-
if (errno != 0)
148-
return (errno);
151+
if ((err = errno) != 0)
152+
return (err);
149153
if (*end != '\0')
150154
return (EINVAL);
151155
if (strchr(val, '-'))

0 commit comments

Comments
 (0)