Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

stricter format checking; fix format call errors

  • Loading branch information...
commit ecfed3d4d5dc3eb73c50f83e19bd013a4d9a5cf7 1 parent da3754d
@kr authored
Showing with 36 additions and 20 deletions.
  1. +8 −8 dat.h
  2. +13 −7 file.c
  3. +1 −1  job.c
  4. +3 −1 mk/inc
  5. +7 −3 prot.c
  6. +4 −0 util.c
View
16 dat.h
@@ -51,11 +51,6 @@ typedef int(FAlloc)(int, int);
#define min(a,b) ((a)<(b)?(a):(b))
-#define twarn(fmt, args...) warn("%s:%d in %s: " fmt, \
- __FILE__, __LINE__, __func__, ##args)
-#define twarnx(fmt, args...) warnx("%s:%d in %s: " fmt, \
- __FILE__, __LINE__, __func__, ##args)
-
#define URGENT_THRESHOLD 1024
#define JOB_DATA_SIZE_LIMIT_DEFAULT ((1 << 16) - 1)
@@ -171,9 +166,14 @@ struct tube {
};
-void warn(const char *fmt, ...);
-void warnx(const char *fmt, ...);
-char* fmtalloc(char *fmt, ...);
+#define twarn(fmt, args...) warn("%s:%d in %s: " fmt, \
+ __FILE__, __LINE__, __func__, ##args)
+#define twarnx(fmt, args...) warnx("%s:%d in %s: " fmt, \
+ __FILE__, __LINE__, __func__, ##args)
+
+void warn(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void warnx(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+char* fmtalloc(char *fmt, ...) __attribute__((format(printf, 1, 2)));
void* zalloc(int n);
#define new(T) zalloc(sizeof(T))
void optparse(Server*, char**);
View
20 file.c
@@ -12,10 +12,11 @@
#include <string.h>
#include "dat.h"
-static void warnpos(File*, int, char*, ...);
static int readrec(File*, job, int*);
static int readrec5(File*, job, int*);
static int readfull(File*, void*, int, int*, char*);
+static void warnpos(File*, int, char*, ...)
+__attribute__((format(printf, 3, 4)));
FAlloc *falloc = &rawfalloc;
@@ -201,7 +202,10 @@ readrec(File *f, job l, int *err)
case Delayed:
if (!j) {
if (jr.body_size > job_data_size_limit) {
- warnpos(f, -r, "job %"PRIu64" is too big (%zd > %zd)", jr.id, job_data_size_limit);
+ warnpos(f, -r, "job %"PRIu64" is too big (%"PRId32" > %zu)",
+ jr.id,
+ jr.body_size,
+ job_data_size_limit);
goto Error;
}
t = tube_find_or_make(tubename);
@@ -217,7 +221,7 @@ readrec(File *f, job l, int *err)
if (namelen) {
if (jr.body_size != j->r.body_size) {
warnpos(f, -r, "job %"PRIu64" size changed", j->r.id);
- warnpos(f, -r, "was %zu, now %zu", j->r.body_size, jr.body_size);
+ warnpos(f, -r, "was %d, now %d", j->r.body_size, jr.body_size);
goto Error;
}
r = readfull(f, j->body, j->r.body_size, err, "job body");
@@ -280,7 +284,7 @@ readrec5(File *f, job l, int *err)
}
sz += r;
if (namelen >= MAX_TUBE_NAME_LEN) {
- warnpos(f, -r, "namelen %d exceeds maximum of %d", namelen, MAX_TUBE_NAME_LEN - 1);
+ warnpos(f, -r, "namelen %zu exceeds maximum of %d", namelen, MAX_TUBE_NAME_LEN - 1);
*err = 1;
return 0;
}
@@ -322,7 +326,10 @@ readrec5(File *f, job l, int *err)
case Delayed:
if (!j) {
if (jr.body_size > job_data_size_limit) {
- warnpos(f, -r, "job %"PRIu64" is too big (%zd > %zd)", jr.id, job_data_size_limit);
+ warnpos(f, -r, "job %"PRIu64" is too big (%"PRId32" > %zu)",
+ jr.id,
+ jr.body_size,
+ job_data_size_limit);
goto Error;
}
t = tube_find_or_make(tubename);
@@ -350,7 +357,7 @@ readrec5(File *f, job l, int *err)
if (namelen) {
if (jr.body_size != j->r.body_size) {
warnpos(f, -r, "job %"PRIu64" size changed", j->r.id);
- warnpos(f, -r, "was %zu, now %zu", j->r.body_size, jr.body_size);
+ warnpos(f, -r, "was %"PRId32", now %"PRId32, j->r.body_size, jr.body_size);
goto Error;
}
r = readfull(f, j->body, j->r.body_size, err, "v5 job body");
@@ -409,7 +416,6 @@ readfull(File *f, void *c, int n, int *err, char *desc)
return r;
}
-
static void
warnpos(File *f, int adj, char *fmt, ...)
{
View
2  job.c
@@ -49,7 +49,7 @@ rehash()
all_jobs_cap = primes[++cur_prime];
all_jobs = calloc(all_jobs_cap, sizeof(job));
if (!all_jobs) {
- twarnx("Failed to allocate %d new hash buckets", all_jobs_cap);
+ twarnx("Failed to allocate %zu new hash buckets", all_jobs_cap);
hash_table_was_oom = 1;
--cur_prime;
all_jobs = old;
View
4 mk/inc
@@ -1,6 +1,8 @@
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
-CFLAGS=-Wall -Werror
+CFLAGS=-Wall -Werror\
+ -Wformat=2\
+
LDFLAGS=
OS=$(shell uname -s | tr A-Z a-z)
INSTALL=install
View
10 prot.c
@@ -314,6 +314,10 @@ protrmdirty(Conn *c)
reply_msg((c),(e)))
static void
+reply_line(Conn*, int, const char*, ...)
+__attribute__((format(printf, 3, 4)));
+
+static void
reply_line(Conn *c, int state, const char *fmt, ...)
{
int r;
@@ -1052,7 +1056,7 @@ do_list_tubes(Conn *c, ms l)
buf[1] = '\n';
c->out_job_sent = 0;
- return reply_line(c, STATE_SENDJOB, "OK %d\r\n", resp_z - 2);
+ return reply_line(c, STATE_SENDJOB, "OK %zu\r\n", resp_z - 2);
}
static int
@@ -1528,7 +1532,7 @@ dispatch_cmd(Conn *c)
TUBE_ASSIGN(t, NULL);
if (!r) return reply_serr(c, MSG_OUT_OF_MEMORY);
- reply_line(c, STATE_SENDWORD, "WATCHING %d\r\n", c->watch.used);
+ reply_line(c, STATE_SENDWORD, "WATCHING %zu\r\n", c->watch.used);
break;
case OP_IGNORE:
name = c->cmd + CMD_IGNORE_LEN;
@@ -1547,7 +1551,7 @@ dispatch_cmd(Conn *c)
if (t) ms_remove(&c->watch, t); /* may free t if refcount => 0 */
t = NULL;
- reply_line(c, STATE_SENDWORD, "WATCHING %d\r\n", c->watch.used);
+ reply_line(c, STATE_SENDWORD, "WATCHING %zu\r\n", c->watch.used);
break;
case OP_QUIT:
connclose(c);
View
4 util.c
@@ -11,6 +11,10 @@ const char *progname;
static void
vwarnx(const char *err, const char *fmt, va_list args)
+__attribute__((format(printf, 2, 0)));
+
+static void
+vwarnx(const char *err, const char *fmt, va_list args)
{
fprintf(stderr, "%s: ", progname);
if (fmt) {
Please sign in to comment.
Something went wrong with that request. Please try again.