From 9b6d6d3133481bf5cbedb9c6c3deecf70868cfb9 Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 11 Feb 2022 14:43:01 -0800 Subject: [PATCH] apple pasteboard Turning on -Wformat-noliteral for Mac triggered a new warning. Blindly suppressing the warning would have silenced it but would also have left a real bug in place. The former format was passing a string argument to %d format. This converts the format to a literal with an additional argument for the non-literal part. It compiles cleanly but I don't know how to test it, let alone force an error for it to report. --- sys/unix/unixmain.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 9f99bb949..59f41a737 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -729,33 +729,33 @@ void port_insert_pastebuf(char *buf) { /* This should be replaced when there is a Cocoa port. */ - const char *errfmt; + const char *errarg; size_t len; FILE *PB = popen("/usr/bin/pbcopy", "w"); if (!PB) { - errfmt = "Unable to start pbcopy (%d)\n"; + errarg = "Unable to start pbcopy"; goto error; } len = strlen(buf); /* Remove the trailing \n, carefully. */ - if (buf[len - 1] == '\n') + if (len > 0 && buf[len - 1] == '\n') len--; /* XXX Sorry, I'm too lazy to write a loop for output this short. */ if (len != fwrite(buf, 1, len, PB)) { - errfmt = "Error sending data to pbcopy (%d)\n"; + errarg = "Error sending data to pbcopy"; goto error; } if (pclose(PB) != -1) { return; } - errfmt = "Error finishing pbcopy (%d)\n"; + errarg = "Error finishing pbcopy"; error: - raw_printf(errfmt, strerror(errno)); + raw_printf("%s: %s (%d)\n", errarg, strerror(errno), errno); } #endif /* __APPLE__ */