From 2e09f166f0107a114d0ebb79e90252c0e5ffb25d Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Tue, 25 Nov 2025 05:16:35 -0500 Subject: [PATCH] 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 Reviewed-by: Rob Norris Signed-off-by: Alexander Motin Closes #17975 --- lib/libspl/tunables.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libspl/tunables.c b/lib/libspl/tunables.c index 67dc9710d..2e4b43d99 100644 --- a/lib/libspl/tunables.c +++ b/lib/libspl/tunables.c @@ -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, '-'))