[PATCH 08/59] misc: Fix clang -Wstring-plus-int warnings on syslog
Sam James
sam@gentoo.org
Wed Oct 22 16:18:58 GMT 2025
> On 22 Oct 2025, at 17:08, Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> wrote:
>
>
>
>> On 20/10/25 16:43, Sam James wrote:
>> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>>
>>> 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 | 5 +++--
>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/misc/syslog.c b/misc/syslog.c
>>> index 4af87f54fd..fab2373089 100644
>>> --- a/misc/syslog.c
>>> +++ b/misc/syslog.c
>>> @@ -31,6 +31,7 @@
>>> static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94";
>>> #endif /* LIBC_SCCS and not lint */
>>>
>>> +#include <libc-diag.h>
>>> #include <libio/libioP.h>
>>> #include <paths.h>
>>> #include <stdarg.h>
>>> @@ -174,7 +175,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]
>>
>> I guess drop the whitespace before [pid?
>
> Right, I will do. Are you ok with this change?
>
>>
OK
>>>
>>> #define SYSLOG_HEADER_WITHOUT_TS(__pri, __msgoff) \
>>> "<%d>: %n", __pri, __msgoff
>>> @@ -274,7 +275,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)
>
More information about the Libc-alpha
mailing list