From: Adhemerval Zanella Date: Fri, 29 Apr 2022 13:50:13 +0000 (-0300) Subject: misc: Fix clang -Wstring-plus-int warnings on syslog X-Git-Tag: glibc-2.43~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e862a07f79e931ac790315ccd7e1942d2b42382;p=thirdparty%2Fglibc.git misc: Fix clang -Wstring-plus-int warnings on syslog clang issues: syslog.c:193:9: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int] 193 | SYSLOG_HEADER (pri, timestamp, &msgoff, pid)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ syslog.c:180:7: note: expanded from macro 'SYSLOG_HEADER' 180 | "[" + (pid == 0), pid, "]" + (pid == 0) Use array indexes instead of string addition (it is simpler than add a supress warning). --- diff --git a/misc/syslog.c b/misc/syslog.c index 4af87f54fd..53bb334259 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -174,7 +174,7 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, "<%d>%s%n%s%s%.0d%s: ", \ __pri, __timestamp, __msgoff, \ LogTag == NULL ? __progname : LogTag, \ - "[" + (pid == 0), pid, "]" + (pid == 0) + &"["[pid == 0], pid, &"]"[pid == 0] #define SYSLOG_HEADER_WITHOUT_TS(__pri, __msgoff) \ "<%d>: %n", __pri, __msgoff @@ -274,7 +274,7 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, /* Output to stderr if requested. */ if (LogStat & LOG_PERROR) __dprintf (STDERR_FILENO, "%s%s", buf + msgoff, - "\n" + (buf[bufsize - 1] == '\n')); + &"\n"[buf[bufsize - 1] == '\n']); /* Get connected, output the message to the local logger. */ if (!connected)