Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | Clang comes up with more printf format warnings |
| 2 | Correcting “format string is not a string literal” warning |
| 3 | requires us to declare that parameter is a printf style |
| 4 | format using the attribute flag |
| 5 | |
| 6 | Upstream-Status: Pending |
| 7 | |
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 9 | |
| 10 | Index: nfs-utils-2.3.3/support/include/xcommon.h |
| 11 | =================================================================== |
| 12 | --- nfs-utils-2.3.3.orig/support/include/xcommon.h |
| 13 | +++ nfs-utils-2.3.3/support/include/xcommon.h |
| 14 | @@ -27,7 +27,7 @@ |
| 15 | |
| 16 | /* Functions in sundries.c that are used in mount.c and umount.c */ |
| 17 | char *canonicalize (const char *path); |
| 18 | -void nfs_error (const char *fmt, ...); |
| 19 | +void nfs_error (const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2))); |
| 20 | void *xmalloc (size_t size); |
| 21 | void *xrealloc(void *p, size_t size); |
| 22 | void xfree(void *); |
| 23 | @@ -36,9 +36,9 @@ char *xstrndup (const char *s, int n); |
| 24 | char *xstrconcat2 (const char *, const char *); |
| 25 | char *xstrconcat3 (const char *, const char *, const char *); |
| 26 | char *xstrconcat4 (const char *, const char *, const char *, const char *); |
| 27 | -void die (int errcode, const char *fmt, ...); |
| 28 | +void die (int errcode, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3))); |
| 29 | |
| 30 | -extern void die(int err, const char *fmt, ...); |
| 31 | +extern void die(int err, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3))); |
| 32 | extern void (*at_die)(void); |
| 33 | |
| 34 | /* exit status - bits below are ORed */ |
| 35 | Index: nfs-utils-2.3.3/support/include/xlog.h |
| 36 | =================================================================== |
| 37 | --- nfs-utils-2.3.3.orig/support/include/xlog.h |
| 38 | +++ nfs-utils-2.3.3/support/include/xlog.h |
| 39 | @@ -43,10 +43,10 @@ void xlog_config(int fac, int on); |
| 40 | void xlog_sconfig(char *, int on); |
| 41 | void xlog_from_conffile(char *); |
| 42 | int xlog_enabled(int fac); |
| 43 | -void xlog(int fac, const char *fmt, ...); |
| 44 | -void xlog_warn(const char *fmt, ...); |
| 45 | -void xlog_err(const char *fmt, ...); |
| 46 | -void xlog_errno(int err, const char *fmt, ...); |
| 47 | -void xlog_backend(int fac, const char *fmt, va_list args); |
| 48 | +void xlog(int fac, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3))); |
| 49 | +void xlog_warn(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2))); |
| 50 | +void xlog_err(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2))); |
| 51 | +void xlog_errno(int err, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3))); |
| 52 | +void xlog_backend(int fac, const char *fmt, va_list args) __attribute__((__format__ (__printf__, 2, 0))); |
| 53 | |
| 54 | #endif /* XLOG_H */ |
| 55 | Index: nfs-utils-2.3.3/support/nfs/xcommon.c |
| 56 | =================================================================== |
| 57 | --- nfs-utils-2.3.3.orig/support/nfs/xcommon.c |
| 58 | +++ nfs-utils-2.3.3/support/nfs/xcommon.c |
| 59 | @@ -93,7 +93,10 @@ nfs_error (const char *fmt, ...) { |
| 60 | |
| 61 | fmt2 = xstrconcat2 (fmt, "\n"); |
| 62 | va_start (args, fmt); |
| 63 | +#pragma clang diagnostic push |
| 64 | +#pragma clang diagnostic ignored "-Wformat-nonliteral" |
| 65 | vfprintf (stderr, fmt2, args); |
| 66 | +#pragma clang diagnostic pop |
| 67 | va_end (args); |
| 68 | free (fmt2); |
| 69 | } |
| 70 | Index: nfs-utils-2.3.3/utils/exportfs/exportfs.c |
| 71 | =================================================================== |
| 72 | --- nfs-utils-2.3.3.orig/utils/exportfs/exportfs.c |
| 73 | +++ nfs-utils-2.3.3/utils/exportfs/exportfs.c |
| 74 | @@ -644,6 +644,7 @@ out: |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | +__attribute__((__format__ (__printf__, 2, 3))) |
| 79 | static char |
| 80 | dumpopt(char c, char *fmt, ...) |
| 81 | { |
| 82 | Index: nfs-utils-2.3.3/utils/statd/statd.c |
| 83 | =================================================================== |
| 84 | --- nfs-utils-2.3.3.orig/utils/statd/statd.c |
| 85 | +++ nfs-utils-2.3.3/utils/statd/statd.c |
| 86 | @@ -136,7 +136,7 @@ static void log_modes(void) |
| 87 | strcat(buf, "TI-RPC "); |
| 88 | #endif |
| 89 | |
| 90 | - xlog_warn(buf); |
| 91 | + xlog_warn("%s", buf); |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | Index: nfs-utils-2.3.3/support/nfs/svc_create.c |
| 96 | =================================================================== |
| 97 | --- nfs-utils-2.3.3.orig/support/nfs/svc_create.c |
| 98 | +++ nfs-utils-2.3.3/support/nfs/svc_create.c |
| 99 | @@ -184,7 +184,7 @@ svc_create_sock(const struct sockaddr *s |
| 100 | type = SOCK_STREAM; |
| 101 | break; |
| 102 | default: |
| 103 | - xlog(D_GENERAL, "%s: Unrecognized bind address semantics: %u", |
| 104 | + xlog(D_GENERAL, "%s: Unrecognized bind address semantics: %lu", |
| 105 | __func__, nconf->nc_semantics); |
| 106 | return -1; |
| 107 | } |
| 108 | Index: nfs-utils-2.3.3/support/nsm/rpc.c |
| 109 | =================================================================== |
| 110 | --- nfs-utils-2.3.3.orig/support/nsm/rpc.c |
| 111 | +++ nfs-utils-2.3.3/support/nsm/rpc.c |
| 112 | @@ -182,7 +182,7 @@ nsm_xmit_getport(const int sock, const s |
| 113 | uint32_t xid; |
| 114 | XDR xdr; |
| 115 | |
| 116 | - xlog(D_CALL, "Sending PMAP_GETPORT for %u, %u, udp", program, version); |
| 117 | + xlog(D_CALL, "Sending PMAP_GETPORT for %lu, %lu, udp", program, version); |
| 118 | |
| 119 | nsm_init_xdrmem(msgbuf, NSM_MAXMSGSIZE, &xdr); |
| 120 | xid = nsm_init_rpc_header(PMAPPROG, PMAPVERS, |
| 121 | Index: nfs-utils-2.3.3/utils/mountd/cache.c |
| 122 | =================================================================== |
| 123 | --- nfs-utils-2.3.3.orig/utils/mountd/cache.c |
| 124 | +++ nfs-utils-2.3.3/utils/mountd/cache.c |
| 125 | @@ -968,8 +968,7 @@ lookup_export(char *dom, char *path, str |
| 126 | } else if (found_type == i && found->m_warned == 0) { |
| 127 | xlog(L_WARNING, "%s exported to both %s and %s, " |
| 128 | "arbitrarily choosing options from first", |
| 129 | - path, found->m_client->m_hostname, exp->m_client->m_hostname, |
| 130 | - dom); |
| 131 | + path, found->m_client->m_hostname, exp->m_client->m_hostname); |
| 132 | found->m_warned = 1; |
| 133 | } |
| 134 | } |
| 135 | Index: nfs-utils-2.3.3/utils/mountd/mountd.c |
| 136 | =================================================================== |
| 137 | --- nfs-utils-2.3.3.orig/utils/mountd/mountd.c |
| 138 | +++ nfs-utils-2.3.3/utils/mountd/mountd.c |
| 139 | @@ -213,7 +213,7 @@ static void |
| 140 | sig_hup (int sig) |
| 141 | { |
| 142 | /* don't exit on SIGHUP */ |
| 143 | - xlog (L_NOTICE, "Received SIGHUP... Ignoring.\n", sig); |
| 144 | + xlog (L_NOTICE, "Received SIGHUP(%d)... Ignoring.\n", sig); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | Index: nfs-utils-2.3.3/utils/statd/rmtcall.c |
| 149 | =================================================================== |
| 150 | --- nfs-utils-2.3.3.orig/utils/statd/rmtcall.c |
| 151 | +++ nfs-utils-2.3.3/utils/statd/rmtcall.c |
| 152 | @@ -247,7 +247,7 @@ process_reply(FD_SET_TYPE *rfds) |
| 153 | xlog_warn("%s: service %d not registered on localhost", |
| 154 | __func__, NL_MY_PROG(lp)); |
| 155 | } else { |
| 156 | - xlog(D_GENERAL, "%s: Callback to %s (for %d) succeeded", |
| 157 | + xlog(D_GENERAL, "%s: Callback to %s (for %s) succeeded", |
| 158 | __func__, NL_MY_NAME(lp), NL_MON_NAME(lp)); |
| 159 | } |
| 160 | nlist_free(¬ify, lp); |
| 161 | Index: nfs-utils-2.3.3/utils/statd/svc_run.c |
| 162 | =================================================================== |
| 163 | --- nfs-utils-2.3.3.orig/utils/statd/svc_run.c |
| 164 | +++ nfs-utils-2.3.3/utils/statd/svc_run.c |
| 165 | @@ -53,6 +53,7 @@ |
| 166 | |
| 167 | #include <errno.h> |
| 168 | #include <time.h> |
| 169 | +#include <inttypes.h> |
| 170 | #include "statd.h" |
| 171 | #include "notlist.h" |
| 172 | |
| 173 | @@ -104,8 +105,8 @@ my_svc_run(int sockfd) |
| 174 | |
| 175 | tv.tv_sec = NL_WHEN(notify) - now; |
| 176 | tv.tv_usec = 0; |
| 177 | - xlog(D_GENERAL, "Waiting for reply... (timeo %d)", |
| 178 | - tv.tv_sec); |
| 179 | + xlog(D_GENERAL, "Waiting for reply... (timeo %jd)", |
| 180 | + (intmax_t)tv.tv_sec); |
| 181 | selret = select(FD_SETSIZE, &readfds, |
| 182 | (void *) 0, (void *) 0, &tv); |
| 183 | } else { |