Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/ntp/dist fix printf format warning with format_arg



details:   https://anonhg.NetBSD.org/src/rev/a18eaf460f24
branches:  trunk
changeset: 972542:a18eaf460f24
user:      christos <christos%NetBSD.org@localhost>
date:      Fri May 29 20:15:37 2020 +0000

description:
fix printf format warning with format_arg

diffstat:

 external/bsd/ntp/dist/include/ntp_stdlib.h |   4 ++-
 external/bsd/ntp/dist/libntp/msyslog.c     |  34 ++++++++++++++---------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diffs (110 lines):

diff -r 80e779c34a31 -r a18eaf460f24 external/bsd/ntp/dist/include/ntp_stdlib.h
--- a/external/bsd/ntp/dist/include/ntp_stdlib.h        Fri May 29 20:15:14 2020 +0000
+++ b/external/bsd/ntp/dist/include/ntp_stdlib.h        Fri May 29 20:15:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_stdlib.h,v 1.16 2020/05/25 20:47:20 christos Exp $ */
+/*     $NetBSD: ntp_stdlib.h,v 1.17 2020/05/29 20:15:37 christos Exp $ */
 
 /*
  * ntp_stdlib.h - Prototypes for NTP lib.
@@ -23,9 +23,11 @@
 #ifdef __GNUC__
 #define NTP_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
 #define NTP_SYSLOG(fmt, args) __attribute__((__format__(__syslog__, fmt, args)))
+#define NTP_FORMAT_ARG(args) __attribute__((__format_arg__(args)))
 #else
 #define NTP_PRINTF(fmt, args)
 #define NTP_SYSLOG(fmt, args)
+#define NTP_FORMAT_ARG(args)
 #endif
 
 extern int     mprintf(const char *, ...) NTP_SYSLOG(1, 2);
diff -r 80e779c34a31 -r a18eaf460f24 external/bsd/ntp/dist/libntp/msyslog.c
--- a/external/bsd/ntp/dist/libntp/msyslog.c    Fri May 29 20:15:14 2020 +0000
+++ b/external/bsd/ntp/dist/libntp/msyslog.c    Fri May 29 20:15:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msyslog.c,v 1.6 2020/05/25 20:47:24 christos Exp $     */
+/*     $NetBSD: msyslog.c,v 1.7 2020/05/29 20:15:38 christos Exp $     */
 
 /*
  * msyslog - either send a message to the terminal or print it on
@@ -44,11 +44,14 @@
 
 /* Declare the local functions */
 void   addto_syslog    (int, const char *);
-#ifndef VSNPRINTF_PERCENT_M
-void   format_errmsg   (char *, size_t, const char *, int);
+#ifdef VSNPRINTF_PERCENT_M
+#define format_errmsg(buf, len, fmt, error) (fmt)
+#else
+static const char *format_errmsg(char *, size_t, const char *, int)
+    NTP_FORMAT_ARG(3);
 
 /* format_errmsg() is under #ifndef VSNPRINTF_PERCENT_M above */
-void
+static const char *
 format_errmsg(
        char *          nfmt,
        size_t          lennfmt,
@@ -86,6 +89,7 @@
                }
        }
        *n = '\0';
+       return nfmt;
 }
 #endif /* VSNPRINTF_PERCENT_M */
 
@@ -233,9 +237,7 @@
        )
 {
 #ifndef VSNPRINTF_PERCENT_M
-       char            nfmt[256];
-#else
-       const char *    nfmt = fmt;
+       char            fmtbuf[256];
 #endif
        int             errval;
 
@@ -248,12 +250,11 @@
 #endif /* SYS_WINNT */
                errval = errno;
 
-#ifndef VSNPRINTF_PERCENT_M
-       format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
-#else
+#ifdef VSNPRINTF_PERCENT_M
        errno = errval;
 #endif
-       return vsnprintf(buf, bufsiz, nfmt, ap);
+       return vsnprintf(buf, bufsiz,
+           format_errmsg(fmtbuf, sizeof(fmtbuf), fmt, errval), ap);
 }
 
 
@@ -265,9 +266,7 @@
        )
 {
 #ifndef VSNPRINTF_PERCENT_M
-       char            nfmt[256];
-#else
-       const char *    nfmt = fmt;
+       char            fmtbuf[256];
 #endif
        int             errval;
 
@@ -280,12 +279,11 @@
 #endif /* SYS_WINNT */
                errval = errno;
 
-#ifndef VSNPRINTF_PERCENT_M
-       format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
-#else
+#ifdef VSNPRINTF_PERCENT_M
        errno = errval;
 #endif
-       return vfprintf(fp, nfmt, ap);
+       return vfprintf(fp, 
+           format_errmsg(fmtbuf, sizeof(fmtbuf), fmt, errval), ap);
 }
 
 



Home | Main Index | Thread Index | Old Index