NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/55311: compilation error (CURRENT, amd64) in /usr/src/external/bsd/ntp/dist/ntpd/ntp_refclock.c, line 1749 : format string is not a string literal



>Number:         55311
>Category:       bin
>Synopsis:       compilation error (CURRENT, amd64) in /usr/src/external/bsd/ntp/dist/ntpd/ntp_refclock.c, line 1749 : format string is not a string literal
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 28 10:15:00 +0000 2020
>Originator:     Rares Aioanei
>Release:        CURRENT
>Organization:
>Environment:
>Description:
Issue is with the fmt argument to vsnprintf, although the warning is totally harmless and the only reason this fails is because we compile with -Werror. 
>How-To-Repeat:
try to compile today's CURRENT amd64 with clang
>Fix:
I suggest using a pragma locally inside refclock_vformat_lcode(). Not a big fan of pragmas, but in this case it is harmless. So the code would look like this : 

void
refclock_vformat_lcode(
        struct refclockproc *   pp,
        char const *            fmt,
        va_list                 va
        )
{
        long len;

        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Wformat-nonliteral"

        len = vsnprintf(pp->a_lastcode, sizeof(pp->a_lastcode), fmt, va);
        if (len <= 0)
                len = 0;
        else if ((size_t)len >= sizeof(pp->a_lastcode))
                len = sizeof(pp->a_lastcode) - 1;

        pp->lencode = (u_short)len;
        pp->a_lastcode[len] = '\0';
        /* !note! the NUL byte is needed in case vsnprintf() really fails */
        #pragma clang diagnostic pop
}

The only changes are the #pragma directives, nothing else, which means no functional changes of any kind. 



Home | Main Index | Thread Index | Old Index