diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c index 32b57ffb6e1a..86ba40234ae4 100644 --- a/lib/libc/gen/uexterr_format.c +++ b/lib/libc/gen/uexterr_format.c @@ -1,31 +1,35 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2025 The FreeBSD Foundation * All rights reserved. * * This software were developed by Konstantin Belousov * under sponsorship from the FreeBSD Foundation. */ #include #include #include #include #include int __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz) { if (bufsz > UEXTERROR_MAXLEN) bufsz = UEXTERROR_MAXLEN; if (ue->error == 0) { strlcpy(buf, "No error", bufsz); return (0); } - snprintf(buf, bufsz, - "errno %d category %u (src line %u) p1 %#jx p2 %#jx %s", - ue->error, ue->cat, ue->src_line, - (uintmax_t)ue->p1, (uintmax_t)ue->p2, ue->msg); + if (ue->msg[0] == '\0') { + snprintf(buf, bufsz, + "errno %d category %u (src line %u) p1 %#jx p2 %#jx", + ue->error, ue->cat, ue->src_line, + (uintmax_t)ue->p1, (uintmax_t)ue->p2); + } else { + strlcpy(buf, ue->msg, bufsz); + } return (0); }