Discussion:
[Dnsmasq-discuss] [PATCH 2/2] Printf related fixes
Rosen Penev
2017-06-26 23:37:30 UTC
Permalink
---
contrib/lease-tools/dhcp_lease_time.c | 8 ++++----
src/auth.c | 6 +++---
src/cache.c | 2 +-
src/dnsmasq.h | 3 +++
src/lease.c | 1 +
src/option.c | 2 +-
src/tftp.c | 2 +-
src/util.c | 8 ++++----
8 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/contrib/lease-tools/dhcp_lease_time.c b/contrib/lease-tools/dhcp_lease_time.c
index fc00ff1..f9d7a85 100644
--- a/contrib/lease-tools/dhcp_lease_time.c
+++ b/contrib/lease-tools/dhcp_lease_time.c
@@ -206,13 +206,13 @@ int main(int argc, char **argv)
{
unsigned int x;
if ((x = t/86400))
- printf("%dd", x);
+ printf("%ud", x);
if ((x = (t/3600)%24))
- printf("%dh", x);
+ printf("%uh", x);
if ((x = (t/60)%60))
- printf("%dm", x);
+ printf("%um", x);
if ((x = t%60))
- printf("%ds", x);
+ printf("%us", x);
}
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 4489eac..2c24e16 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -597,12 +597,12 @@ size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, time_t n
char *p = name;

if (subnet->prefixlen >= 24)
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
if (subnet->prefixlen >= 16 )
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
- p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
+ p += sprintf(p, "%u.in-addr.arpa", a & 0xff);

}
#ifdef HAVE_IPV6
diff --git a/src/cache.c b/src/cache.c
index bf585fe..a719d95 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1511,7 +1511,7 @@ void dump_cache(time_t now)
/* ctime includes trailing \n - eat it */
*(p-1) = 0;
#endif
- my_syslog(LOG_INFO, daemon->namebuff);
+ my_syslog(LOG_INFO, "%s", daemon->namebuff);
}
}
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 84083cc..44e26c7 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1212,7 +1212,10 @@ int wildcard_matchn(const char* wildcard, const char* match, int num);
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
int log_reopen(char *log_file);
+
+__attribute__ ((format (printf, 2, 3)))
void my_syslog(int priority, const char *format, ...);
+
void set_log_writer(void);
void check_log_writer(int force);
void flush_log(void);
diff --git a/src/lease.c b/src/lease.c
index 634372d..1970ba9 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -230,6 +230,7 @@ void lease_update_from_configs(void)
lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
}

+__attribute__ ((format (printf, 2, 3)))
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/option.c b/src/option.c
index 78ad81e..6a14c4d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -882,7 +882,7 @@ static struct server *add_rev4(struct in_addr addr, int msize)
switch (msize)
{
case 32:
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
/* fall through */
case 24:
p += sprintf(p, "%d.", (a >> 8) & 0xff);
diff --git a/src/tftp.c b/src/tftp.c
index 8b27c7b..131e6de 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -734,7 +734,7 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
if (transfer->opt_blocksize)
{
p += (sprintf(p, "blksize") + 1);
- p += (sprintf(p, "%d", transfer->blocksize) + 1);
+ p += (sprintf(p, "%u", transfer->blocksize) + 1);
}
if (transfer->opt_transize)
{
diff --git a/src/util.c b/src/util.c
index 66128a9..bb6dba3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -448,13 +448,13 @@ void prettyprint_time(char *buf, unsigned int t)
{
unsigned int x, p = 0;
if ((x = t/86400))
- p += sprintf(&buf[p], "%dd", x);
+ p += sprintf(&buf[p], "%ud", x);
if ((x = (t/3600)%24))
- p += sprintf(&buf[p], "%dh", x);
+ p += sprintf(&buf[p], "%uh", x);
if ((x = (t/60)%60))
- p += sprintf(&buf[p], "%dm", x);
+ p += sprintf(&buf[p], "%um", x);
if ((x = t%60))
- p += sprintf(&buf[p], "%ds", x);
+ p += sprintf(&buf[p], "%us", x);
}
}
--
2.9.4
Simon Kelley
2017-06-27 21:31:19 UTC
Permalink
Patch applied. Many thanks.


Cheers,

Simon.
---
src/dnsmasq.h | 38 +++++++++++++++++++-------------------
src/lease.c | 2 +-
src/rfc2131.c | 10 +++++-----
src/tftp.c | 2 +-
4 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 2885c29..84083cc 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1130,18 +1130,18 @@ unsigned int extract_request(struct dns_header *header, size_t qlen,
char *name, unsigned short *typep);
size_t setup_reply(struct dns_header *header, size_t qlen,
struct all_addr *addrp, unsigned int flags,
- unsigned long local_ttl);
-int extract_addresses(struct dns_header *header, size_t qlen, char *namebuff,
- time_t now, char **ipsets, int is_sign, int checkrebind,
- int no_cache, int secure, int *doctored);
+ unsigned long ttl);
+int extract_addresses(struct dns_header *header, size_t qlen, char *name,
+ time_t now, char **ipsets, int is_sign, int check_rebind,
+ int no_cache_dnssec, int secure, int *doctored);
size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
struct in_addr local_addr, struct in_addr local_netmask,
time_t now, int ad_reqd, int do_bit, int have_pseudoheader);
int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
- struct bogus_addr *addr, time_t now);
+ struct bogus_addr *baddr, time_t now);
int check_for_ignored_address(struct dns_header *header, size_t qlen, struct bogus_addr *baddr);
int check_for_local_domain(char *name, time_t now);
-unsigned int questions_crc(struct dns_header *header, size_t plen, char *buff);
+unsigned int questions_crc(struct dns_header *header, size_t plen, char *name);
size_t resize_packet(struct dns_header *header, size_t plen,
unsigned char *pheader, size_t hlen);
int add_resource_record(struct dns_header *header, char *limit, int *truncp,
@@ -1163,11 +1163,11 @@ int in_zone(struct auth_zone *zone, char *name, char **cut);
/* dnssec.c */
size_t dnssec_generate_query(struct dns_header *header, unsigned char *end, char *name, int class, int type, union mysockaddr *addr, int edns_pktsz);
-int dnssec_validate_by_ds(time_t now, struct dns_header *header, size_t n, char *name, char *keyname, int class);
+int dnssec_validate_by_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class);
int dnssec_validate_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class);
int dnssec_validate_reply(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int *class,
int check_unsigned, int *neganswer, int *nons);
-int dnskey_keytag(int alg, int flags, unsigned char *rdata, int rdlen);
+int dnskey_keytag(int alg, int flags, unsigned char *key, int keylen);
size_t filter_rrsigs(struct dns_header *header, size_t plen);
unsigned char* hash_questions(struct dns_header *header, size_t plen, char *name);
int setup_timestamp(void);
@@ -1177,8 +1177,8 @@ void rand_init(void);
unsigned short rand16(void);
u32 rand32(void);
u64 rand64(void);
-int legal_hostname(char *c);
-char *canonicalise(char *s, int *nomem);
+int legal_hostname(char *name);
+char *canonicalise(char *in, int *nomem);
unsigned char *do_rfc1035_name(unsigned char *p, char *sval);
void *safe_malloc(size_t size);
void safe_pipe(int *fd, int read_noblock);
@@ -1240,7 +1240,7 @@ struct frec *get_new_frec(time_t now, int *wait, int force);
int send_from(int fd, int nowild, char *packet, size_t len,
union mysockaddr *to, struct all_addr *source,
unsigned int iface);
-void resend_query();
+void resend_query(void);
struct randfd *allocate_rfd(int family);
void free_rfd(struct randfd *rfd);
@@ -1260,12 +1260,12 @@ void add_update_server(int flags,
void check_servers(void);
int enumerate_interfaces(int reset);
void create_wildcard_listeners(void);
-void create_bound_listeners(int die);
+void create_bound_listeners(int dienow);
void warn_bound_listeners(void);
void warn_wild_labels(void);
void warn_int_names(void);
int is_dad_listeners(void);
-int iface_check(int family, struct all_addr *addr, char *name, int *auth_dns);
+int iface_check(int family, struct all_addr *addr, char *name, int *auth);
int loopback_exception(int fd, int family, struct all_addr *addr, char *name);
int label_exception(int index, int family, struct all_addr *addr);
int fix_fd(int fd);
@@ -1286,7 +1286,7 @@ void newaddress(time_t now);
void dhcp_init(void);
void dhcp_packet(time_t now, int pxe_fd);
struct dhcp_context *address_available(struct dhcp_context *context,
- struct in_addr addr,
+ struct in_addr taddr,
struct dhcp_netid *netids);
struct dhcp_context *narrow_context(struct dhcp_context *context,
struct in_addr taddr,
@@ -1345,7 +1345,7 @@ void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data,
#ifdef HAVE_DHCP
size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
size_t sz, time_t now, int unicast_dest, int loopback,
- int *is_inform, int pxe_fd, struct in_addr fallback, time_t recvtime);
+ int *is_inform, int pxe, struct in_addr fallback, time_t recvtime);
unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr,
int clid_len, unsigned char *clid, int *len_out);
#endif
@@ -1460,10 +1460,10 @@ unsigned short relay_reply6( struct sockaddr_in6 *peer, ssize_t sz, char *arriva
#ifdef HAVE_DHCP
void dhcp_common_init(void);
ssize_t recv_dhcp_packet(int fd, struct msghdr *msg);
-struct dhcp_netid *run_tag_if(struct dhcp_netid *input);
+struct dhcp_netid *run_tag_if(struct dhcp_netid *tags);
struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags,
struct dhcp_opt *opts);
-int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
+int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded);
char *strip_hostname(char *hostname);
void log_tags(struct dhcp_netid *netid, u32 xid);
int match_bytes(struct dhcp_opt *o, unsigned char *p, int len);
@@ -1521,13 +1521,13 @@ void slaac_ping_reply(struct in6_addr *sender, unsigned char *packet, char *inte
/* loop.c */
#ifdef HAVE_LOOP
-void loop_send_probes();
+void loop_send_probes(void);
int detect_loop(char *query, int type);
#endif
/* inotify.c */
#ifdef HAVE_INOTIFY
-void inotify_dnsmasq_init();
+void inotify_dnsmasq_init(void);
int inotify_check(time_t now);
void set_dynamic_inotify(int flag, int total_size, struct crec **rhash, int revhashsz);
#endif
diff --git a/src/lease.c b/src/lease.c
index efa0a30..634372d 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -229,7 +229,7 @@ void lease_update_from_configs(void)
else if ((name = host_from_dns(lease->addr)))
lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
}
-
+
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/rfc2131.c b/src/rfc2131.c
index 6e95e36..86230b4 100644
--- a/src/rfc2131.c
+++ b/src/rfc2131.c
@@ -32,7 +32,7 @@ static void option_put(struct dhcp_packet *mess, unsigned char *end, int opt, in
static void option_put_string(struct dhcp_packet *mess, unsigned char *end,
int opt, char *string, int null_term);
static struct in_addr option_addr(unsigned char *opt);
-static unsigned int option_uint(unsigned char *opt, int i, int size);
+static unsigned int option_uint(unsigned char *opt, int offset, int size);
static void log_packet(char *type, void *addr, unsigned char *ext_mac,
int mac_len, char *interface, char *string, char *err, u32 xid);
static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt_type, int minsize);
@@ -42,14 +42,14 @@ static void clear_packet(struct dhcp_packet *mess, unsigned char *end);
static int in_list(unsigned char *list, int opt);
static void do_options(struct dhcp_context *context,
struct dhcp_packet *mess,
- unsigned char *real_end,
+ unsigned char *end,
unsigned char *req_options,
char *hostname,
- char *config_domain,
+ char *domain,
struct dhcp_netid *netid,
struct in_addr subnet_addr,
unsigned char fqdn_flags,
- int null_term, int pxearch,
+ int null_term, int pxe_arch,
unsigned char *uuid,
int vendor_class_len,
time_t now,
@@ -58,7 +58,7 @@ static void do_options(struct dhcp_context *context,
static void match_vendor_opts(unsigned char *opt, struct dhcp_opt *dopt);
-static int do_encap_opts(struct dhcp_opt *opts, int encap, int flag, struct dhcp_packet *mess, unsigned char *end, int null_term);
+static int do_encap_opts(struct dhcp_opt *opt, int encap, int flag, struct dhcp_packet *mess, unsigned char *end, int null_term);
static void pxe_misc(struct dhcp_packet *mess, unsigned char *end, unsigned char *uuid);
static int prune_vendor_opts(struct dhcp_netid *netid);
static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct in_addr local, time_t now);
diff --git a/src/tftp.c b/src/tftp.c
index 37203d3..8b27c7b 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -20,7 +20,7 @@
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix);
static void free_transfer(struct tftp_transfer *transfer);
-static ssize_t tftp_err(int err, char *packet, char *mess, char *file);
+static ssize_t tftp_err(int err, char *packet, char *message, char *file);
static ssize_t tftp_err_oops(char *packet, char *file);
static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
static char *next(char **p, char *end);
Simon Kelley
2017-06-27 21:31:57 UTC
Permalink
Patch applied, with the exception of the gcc-specific __attribute__ stuff.


Cheers,

Simon.
Post by Rosen Penev
---
contrib/lease-tools/dhcp_lease_time.c | 8 ++++----
src/auth.c | 6 +++---
src/cache.c | 2 +-
src/dnsmasq.h | 3 +++
src/lease.c | 1 +
src/option.c | 2 +-
src/tftp.c | 2 +-
src/util.c | 8 ++++----
8 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/contrib/lease-tools/dhcp_lease_time.c b/contrib/lease-tools/dhcp_lease_time.c
index fc00ff1..f9d7a85 100644
--- a/contrib/lease-tools/dhcp_lease_time.c
+++ b/contrib/lease-tools/dhcp_lease_time.c
@@ -206,13 +206,13 @@ int main(int argc, char **argv)
{
unsigned int x;
if ((x = t/86400))
- printf("%dd", x);
+ printf("%ud", x);
if ((x = (t/3600)%24))
- printf("%dh", x);
+ printf("%uh", x);
if ((x = (t/60)%60))
- printf("%dm", x);
+ printf("%um", x);
if ((x = t%60))
- printf("%ds", x);
+ printf("%us", x);
}
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 4489eac..2c24e16 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -597,12 +597,12 @@ size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, time_t n
char *p = name;
if (subnet->prefixlen >= 24)
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
if (subnet->prefixlen >= 16 )
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
- p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
+ p += sprintf(p, "%u.in-addr.arpa", a & 0xff);
}
#ifdef HAVE_IPV6
diff --git a/src/cache.c b/src/cache.c
index bf585fe..a719d95 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1511,7 +1511,7 @@ void dump_cache(time_t now)
/* ctime includes trailing \n - eat it */
*(p-1) = 0;
#endif
- my_syslog(LOG_INFO, daemon->namebuff);
+ my_syslog(LOG_INFO, "%s", daemon->namebuff);
}
}
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 84083cc..44e26c7 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1212,7 +1212,10 @@ int wildcard_matchn(const char* wildcard, const char* match, int num);
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
int log_reopen(char *log_file);
+
+__attribute__ ((format (printf, 2, 3)))
void my_syslog(int priority, const char *format, ...);
+
void set_log_writer(void);
void check_log_writer(int force);
void flush_log(void);
diff --git a/src/lease.c b/src/lease.c
index 634372d..1970ba9 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -230,6 +230,7 @@ void lease_update_from_configs(void)
lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
}
+__attribute__ ((format (printf, 2, 3)))
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/option.c b/src/option.c
index 78ad81e..6a14c4d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -882,7 +882,7 @@ static struct server *add_rev4(struct in_addr addr, int msize)
switch (msize)
{
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
/* fall through */
p += sprintf(p, "%d.", (a >> 8) & 0xff);
diff --git a/src/tftp.c b/src/tftp.c
index 8b27c7b..131e6de 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -734,7 +734,7 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
if (transfer->opt_blocksize)
{
p += (sprintf(p, "blksize") + 1);
- p += (sprintf(p, "%d", transfer->blocksize) + 1);
+ p += (sprintf(p, "%u", transfer->blocksize) + 1);
}
if (transfer->opt_transize)
{
diff --git a/src/util.c b/src/util.c
index 66128a9..bb6dba3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -448,13 +448,13 @@ void prettyprint_time(char *buf, unsigned int t)
{
unsigned int x, p = 0;
if ((x = t/86400))
- p += sprintf(&buf[p], "%dd", x);
+ p += sprintf(&buf[p], "%ud", x);
if ((x = (t/3600)%24))
- p += sprintf(&buf[p], "%dh", x);
+ p += sprintf(&buf[p], "%uh", x);
if ((x = (t/60)%60))
- p += sprintf(&buf[p], "%dm", x);
+ p += sprintf(&buf[p], "%um", x);
if ((x = t%60))
- p += sprintf(&buf[p], "%ds", x);
+ p += sprintf(&buf[p], "%us", x);
}
}
Rosen Penev
2017-06-28 02:20:39 UTC
Permalink
AFAIK Clang and GCC both support it. Any other relevant compilers?
Post by Simon Kelley
Patch applied, with the exception of the gcc-specific __attribute__ stuff.
Cheers,
Simon.
Post by Rosen Penev
---
contrib/lease-tools/dhcp_lease_time.c | 8 ++++----
src/auth.c | 6 +++---
src/cache.c | 2 +-
src/dnsmasq.h | 3 +++
src/lease.c | 1 +
src/option.c | 2 +-
src/tftp.c | 2 +-
src/util.c | 8 ++++----
8 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/contrib/lease-tools/dhcp_lease_time.c
b/contrib/lease-tools/dhcp_lease_time.c
Post by Rosen Penev
index fc00ff1..f9d7a85 100644
--- a/contrib/lease-tools/dhcp_lease_time.c
+++ b/contrib/lease-tools/dhcp_lease_time.c
@@ -206,13 +206,13 @@ int main(int argc, char **argv)
{
unsigned int x;
if ((x = t/86400))
- printf("%dd", x);
+ printf("%ud", x);
if ((x = (t/3600)%24))
- printf("%dh", x);
+ printf("%uh", x);
if ((x = (t/60)%60))
- printf("%dm", x);
+ printf("%um", x);
if ((x = t%60))
- printf("%ds", x);
+ printf("%us", x);
}
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 4489eac..2c24e16 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -597,12 +597,12 @@ size_t answer_auth(struct dns_header *header, char
*limit, size_t qlen, time_t n
Post by Rosen Penev
char *p = name;
if (subnet->prefixlen >= 24)
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
if (subnet->prefixlen >= 16 )
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
- p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
+ p += sprintf(p, "%u.in-addr.arpa", a & 0xff);
}
#ifdef HAVE_IPV6
diff --git a/src/cache.c b/src/cache.c
index bf585fe..a719d95 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1511,7 +1511,7 @@ void dump_cache(time_t now)
/* ctime includes trailing \n - eat it */
*(p-1) = 0;
#endif
- my_syslog(LOG_INFO, daemon->namebuff);
+ my_syslog(LOG_INFO, "%s", daemon->namebuff);
}
}
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 84083cc..44e26c7 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1212,7 +1212,10 @@ int wildcard_matchn(const char* wildcard, const
char* match, int num);
Post by Rosen Penev
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
int log_reopen(char *log_file);
+
+__attribute__ ((format (printf, 2, 3)))
void my_syslog(int priority, const char *format, ...);
+
void set_log_writer(void);
void check_log_writer(int force);
void flush_log(void);
diff --git a/src/lease.c b/src/lease.c
index 634372d..1970ba9 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -230,6 +230,7 @@ void lease_update_from_configs(void)
lease_set_hostname(lease, name, 1, get_domain(lease->addr),
NULL); /* updates auth flag only */
Post by Rosen Penev
}
+__attribute__ ((format (printf, 2, 3)))
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/option.c b/src/option.c
index 78ad81e..6a14c4d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -882,7 +882,7 @@ static struct server *add_rev4(struct in_addr addr,
int msize)
Post by Rosen Penev
switch (msize)
{
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
/* fall through */
p += sprintf(p, "%d.", (a >> 8) & 0xff);
diff --git a/src/tftp.c b/src/tftp.c
index 8b27c7b..131e6de 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -734,7 +734,7 @@ static ssize_t get_block(char *packet, struct
tftp_transfer *transfer)
Post by Rosen Penev
if (transfer->opt_blocksize)
{
p += (sprintf(p, "blksize") + 1);
- p += (sprintf(p, "%d", transfer->blocksize) + 1);
+ p += (sprintf(p, "%u", transfer->blocksize) + 1);
}
if (transfer->opt_transize)
{
diff --git a/src/util.c b/src/util.c
index 66128a9..bb6dba3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -448,13 +448,13 @@ void prettyprint_time(char *buf, unsigned int t)
{
unsigned int x, p = 0;
if ((x = t/86400))
- p += sprintf(&buf[p], "%dd", x);
+ p += sprintf(&buf[p], "%ud", x);
if ((x = (t/3600)%24))
- p += sprintf(&buf[p], "%dh", x);
+ p += sprintf(&buf[p], "%uh", x);
if ((x = (t/60)%60))
- p += sprintf(&buf[p], "%dm", x);
+ p += sprintf(&buf[p], "%um", x);
if ((x = t%60))
- p += sprintf(&buf[p], "%ds", x);
+ p += sprintf(&buf[p], "%us", x);
}
}
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Simon Kelley
2017-06-28 20:59:49 UTC
Permalink
Post by Rosen Penev
AFAIK Clang and GCC both support it. Any other relevant compilers?
What do *BSD use? dnsmasq supports them? Policy is C89 and always has been.


Cheers,

Simon.
Post by Rosen Penev
Patch applied, with the exception of the gcc-specific __attribute__ stuff.
Cheers,
Simon.
Post by Rosen Penev
---
contrib/lease-tools/dhcp_lease_time.c | 8 ++++----
src/auth.c | 6 +++---
src/cache.c | 2 +-
src/dnsmasq.h | 3 +++
src/lease.c | 1 +
src/option.c | 2 +-
src/tftp.c | 2 +-
src/util.c | 8 ++++----
8 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/contrib/lease-tools/dhcp_lease_time.c
b/contrib/lease-tools/dhcp_lease_time.c
Post by Rosen Penev
index fc00ff1..f9d7a85 100644
--- a/contrib/lease-tools/dhcp_lease_time.c
+++ b/contrib/lease-tools/dhcp_lease_time.c
@@ -206,13 +206,13 @@ int main(int argc, char **argv)
{
unsigned int x;
if ((x = t/86400))
- printf("%dd", x);
+ printf("%ud", x);
if ((x = (t/3600)%24))
- printf("%dh", x);
+ printf("%uh", x);
if ((x = (t/60)%60))
- printf("%dm", x);
+ printf("%um", x);
if ((x = t%60))
- printf("%ds", x);
+ printf("%us", x);
}
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 4489eac..2c24e16 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -597,12 +597,12 @@ size_t answer_auth(struct dns_header
*header, char *limit, size_t qlen, time_t n
Post by Rosen Penev
char *p = name;
if (subnet->prefixlen >= 24)
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
if (subnet->prefixlen >= 16 )
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
- p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
+ p += sprintf(p, "%u.in-addr.arpa", a & 0xff);
}
#ifdef HAVE_IPV6
diff --git a/src/cache.c b/src/cache.c
index bf585fe..a719d95 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1511,7 +1511,7 @@ void dump_cache(time_t now)
/* ctime includes trailing \n - eat it */
*(p-1) = 0;
#endif
- my_syslog(LOG_INFO, daemon->namebuff);
+ my_syslog(LOG_INFO, "%s", daemon->namebuff);
}
}
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 84083cc..44e26c7 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1212,7 +1212,10 @@ int wildcard_matchn(const char* wildcard,
const char* match, int num);
Post by Rosen Penev
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
int log_reopen(char *log_file);
+
+__attribute__ ((format (printf, 2, 3)))
void my_syslog(int priority, const char *format, ...);
+
void set_log_writer(void);
void check_log_writer(int force);
void flush_log(void);
diff --git a/src/lease.c b/src/lease.c
index 634372d..1970ba9 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -230,6 +230,7 @@ void lease_update_from_configs(void)
lease_set_hostname(lease, name, 1, get_domain(lease->addr),
NULL); /* updates auth flag only */
Post by Rosen Penev
}
+__attribute__ ((format (printf, 2, 3)))
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/option.c b/src/option.c
index 78ad81e..6a14c4d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -882,7 +882,7 @@ static struct server *add_rev4(struct in_addr
addr, int msize)
Post by Rosen Penev
switch (msize)
{
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
/* fall through */
p += sprintf(p, "%d.", (a >> 8) & 0xff);
diff --git a/src/tftp.c b/src/tftp.c
index 8b27c7b..131e6de 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -734,7 +734,7 @@ static ssize_t get_block(char *packet, struct
tftp_transfer *transfer)
Post by Rosen Penev
if (transfer->opt_blocksize)
{
p += (sprintf(p, "blksize") + 1);
- p += (sprintf(p, "%d", transfer->blocksize) + 1);
+ p += (sprintf(p, "%u", transfer->blocksize) + 1);
}
if (transfer->opt_transize)
{
diff --git a/src/util.c b/src/util.c
index 66128a9..bb6dba3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -448,13 +448,13 @@ void prettyprint_time(char *buf, unsigned int t)
{
unsigned int x, p = 0;
if ((x = t/86400))
- p += sprintf(&buf[p], "%dd", x);
+ p += sprintf(&buf[p], "%ud", x);
if ((x = (t/3600)%24))
- p += sprintf(&buf[p], "%dh", x);
+ p += sprintf(&buf[p], "%uh", x);
if ((x = (t/60)%60))
- p += sprintf(&buf[p], "%dm", x);
+ p += sprintf(&buf[p], "%um", x);
if ((x = t%60))
- p += sprintf(&buf[p], "%ds", x);
+ p += sprintf(&buf[p], "%us", x);
}
}
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Rosen Penev
2017-06-28 21:21:49 UTC
Permalink
As far as I can tell, BSDs use GCC 4.2.1 because of GPLv2. The format
attribute has been supported since at least 3.3.2. It's not a C89 issue.
Clang has always supported the attribute. Most BSDs have migrated to Clang
because of License.

Not that I'm against removing the attribute. Just curious about the reason.
Avoiding potential breakage is good.
Post by Simon Kelley
Post by Rosen Penev
AFAIK Clang and GCC both support it. Any other relevant compilers?
What do *BSD use? dnsmasq supports them? Policy is C89 and always has been.
Cheers,
Simon.
Post by Rosen Penev
Patch applied, with the exception of the gcc-specific __attribute__ stuff.
Cheers,
Simon.
Post by Rosen Penev
---
contrib/lease-tools/dhcp_lease_time.c | 8 ++++----
src/auth.c | 6 +++---
src/cache.c | 2 +-
src/dnsmasq.h | 3 +++
src/lease.c | 1 +
src/option.c | 2 +-
src/tftp.c | 2 +-
src/util.c | 8 ++++----
8 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/contrib/lease-tools/dhcp_lease_time.c
b/contrib/lease-tools/dhcp_lease_time.c
Post by Rosen Penev
index fc00ff1..f9d7a85 100644
--- a/contrib/lease-tools/dhcp_lease_time.c
+++ b/contrib/lease-tools/dhcp_lease_time.c
@@ -206,13 +206,13 @@ int main(int argc, char **argv)
{
unsigned int x;
if ((x = t/86400))
- printf("%dd", x);
+ printf("%ud", x);
if ((x = (t/3600)%24))
- printf("%dh", x);
+ printf("%uh", x);
if ((x = (t/60)%60))
- printf("%dm", x);
+ printf("%um", x);
if ((x = t%60))
- printf("%ds", x);
+ printf("%us", x);
}
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 4489eac..2c24e16 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -597,12 +597,12 @@ size_t answer_auth(struct dns_header
*header, char *limit, size_t qlen, time_t n
Post by Rosen Penev
char *p = name;
if (subnet->prefixlen >= 24)
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
if (subnet->prefixlen >= 16 )
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
a = a >> 8;
- p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
+ p += sprintf(p, "%u.in-addr.arpa", a & 0xff);
}
#ifdef HAVE_IPV6
diff --git a/src/cache.c b/src/cache.c
index bf585fe..a719d95 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1511,7 +1511,7 @@ void dump_cache(time_t now)
/* ctime includes trailing \n - eat it */
*(p-1) = 0;
#endif
- my_syslog(LOG_INFO, daemon->namebuff);
+ my_syslog(LOG_INFO, "%s", daemon->namebuff);
}
}
}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 84083cc..44e26c7 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1212,7 +1212,10 @@ int wildcard_matchn(const char* wildcard,
const char* match, int num);
Post by Rosen Penev
void die(char *message, char *arg1, int exit_code);
int log_start(struct passwd *ent_pw, int errfd);
int log_reopen(char *log_file);
+
+__attribute__ ((format (printf, 2, 3)))
void my_syslog(int priority, const char *format, ...);
+
void set_log_writer(void);
void check_log_writer(int force);
void flush_log(void);
diff --git a/src/lease.c b/src/lease.c
index 634372d..1970ba9 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -230,6 +230,7 @@ void lease_update_from_configs(void)
lease_set_hostname(lease, name, 1, get_domain(lease->addr),
NULL); /* updates auth flag only */
Post by Rosen Penev
}
+__attribute__ ((format (printf, 2, 3)))
static void ourprintf(int *errp, char *format, ...)
{
va_list ap;
diff --git a/src/option.c b/src/option.c
index 78ad81e..6a14c4d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -882,7 +882,7 @@ static struct server *add_rev4(struct in_addr
addr, int msize)
Post by Rosen Penev
switch (msize)
{
- p += sprintf(p, "%d.", a & 0xff);
+ p += sprintf(p, "%u.", a & 0xff);
/* fall through */
p += sprintf(p, "%d.", (a >> 8) & 0xff);
diff --git a/src/tftp.c b/src/tftp.c
index 8b27c7b..131e6de 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -734,7 +734,7 @@ static ssize_t get_block(char *packet, struct
tftp_transfer *transfer)
Post by Rosen Penev
if (transfer->opt_blocksize)
{
p += (sprintf(p, "blksize") + 1);
- p += (sprintf(p, "%d", transfer->blocksize) + 1);
+ p += (sprintf(p, "%u", transfer->blocksize) + 1);
}
if (transfer->opt_transize)
{
diff --git a/src/util.c b/src/util.c
index 66128a9..bb6dba3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -448,13 +448,13 @@ void prettyprint_time(char *buf, unsigned
int t)
Post by Rosen Penev
Post by Rosen Penev
{
unsigned int x, p = 0;
if ((x = t/86400))
- p += sprintf(&buf[p], "%dd", x);
+ p += sprintf(&buf[p], "%ud", x);
if ((x = (t/3600)%24))
- p += sprintf(&buf[p], "%dh", x);
+ p += sprintf(&buf[p], "%uh", x);
if ((x = (t/60)%60))
- p += sprintf(&buf[p], "%dm", x);
+ p += sprintf(&buf[p], "%um", x);
if ((x = t%60))
- p += sprintf(&buf[p], "%ds", x);
+ p += sprintf(&buf[p], "%us", x);
}
}
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Kurt H Maier
2017-06-28 23:55:01 UTC
Permalink
Post by Rosen Penev
As far as I can tell, BSDs use GCC 4.2.1 because of GPLv2. The format
attribute has been supported since at least 3.3.2. It's not a C89 issue.
Clang has always supported the attribute. Most BSDs have migrated to Clang
because of License.
Not that I'm against removing the attribute. Just curious about the reason.
Avoiding potential breakage is good.
Regardless of clang's support (and clang has a different set of
supported attributes than GCC), the __attribute__ stuff is not part of
any standard whatsoever and is therefore untrustworthy. It only exists
because #pragma hadn't matured, and clang only supports it because it is
trying to be compatible. It would be better to find a different way.

khm

Loading...