]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
misc: Fix clang -Wstring-plus-int warnings on syslog
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 29 Apr 2022 13:50:13 +0000 (10:50 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 22 Oct 2025 19:35:39 +0000 (16:35 -0300)
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).

misc/syslog.c

index 4af87f54fdbe49bec65c637cab3a6e2397fe33ba..53bb33425918d10d68e21e3787a8bc27ee873f57 100644 (file)
@@ -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)