From d5cc0c3b8a8ca95050d46421fa83d7c5c1eaacb8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 18 Sep 2025 23:19:01 +0200 Subject: [PATCH] maint: ln: eliminate a clang -Wformat-extra-args warning * src/ln.c (do_link): Don't pass unused arguments to error(). Don't use "%.0s" to consume a string argument without printing it. --- src/ln.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ln.c b/src/ln.c index 3a40244fb7..7a366bc907 100644 --- a/src/ln.c +++ b/src/ln.c @@ -369,18 +369,31 @@ do_link (char const *source, int destdir_fd, char const *dest_base, } else { - error (0, link_errno, - (symbolic_link - ? (link_errno != ENAMETOOLONG && *source - ? _("failed to create symbolic link %s") - : _("failed to create symbolic link %s -> %s")) - : (link_errno == EMLINK - ? _("failed to create hard link to %.0s%s") - : (link_errno == EDQUOT || link_errno == EEXIST - || link_errno == ENOSPC || link_errno == EROFS) - ? _("failed to create hard link %s") - : _("failed to create hard link %s => %s"))), - quoteaf_n (0, dest), quoteaf_n (1, source)); + char *dest_quoted = quoteaf_n (0, dest); + char *source_quoted = quoteaf_n (1, source); + + if (symbolic_link) + { + if (link_errno != ENAMETOOLONG && *source) + error (0, link_errno, _("failed to create symbolic link %s"), + dest_quoted); + else + error (0, link_errno, _("failed to create symbolic link %s -> %s"), + dest_quoted, source_quoted); + } + else + { + if (link_errno == EMLINK) + error (0, link_errno, _("failed to create hard link to %s"), + source_quoted); + else if (link_errno == EDQUOT || link_errno == EEXIST + || link_errno == ENOSPC || link_errno == EROFS) + error (0, link_errno, _("failed to create hard link %s"), + dest_quoted); + else + error (0, link_errno, _("failed to create hard link %s => %s"), + dest_quoted, source_quoted); + } if (backup_base) { -- 2.47.3