Skip to content

Commit

Permalink
Fix compilation warnings about log sprintf format strings
Browse files Browse the repository at this point in the history
The size of the difference between two pointers
depends on the platform (e.g. 64bit vs 32bit pointers),
so cast it to an integer - it should fit in that range anyway.
  • Loading branch information
TysonAndre committed Jul 1, 2021
1 parent 3f7cc0c commit 709de01
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ Makefile.in

# The .clang-format.example file may be copied here for use with -style=file
.clang-format

test_all
*.trs
tags

3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
Fix memory leak bug for redis mset (deep011)
Support arbitrarily deep nested redis multi-bulk
responses (nested arrays) (qingping209, tyson)
Upgrade from libyaml 0.1.4 to 0.2.5 (tyson)
Fix compiler warnings about wrong conversion specifiers in format
strings for logging (tyson)

2015-22-06 Manju Rajashekhar <[email protected]>
* twemproxy: version 0.4.1 release
Expand Down
3 changes: 2 additions & 1 deletion ci/build-nutcracker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ trap cleanup INT
cleanup

export CFLAGS="-O3 -fno-strict-aliasing -I/usr/lib/x86_64-redhat-linux6E/include -B /usr/lib/x86_64-redhat-linux6E/lib64"
# TODO: Figure out how to make this apply only to the contrib/ directory. Maybe override the yaml directory's Makefile.am after extracting it.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
CFLAGS+=" -Werror -Wall -Wno-pointer-sign -Wno-sign-conversion -Wno-missing-braces -Wno-unused-value -Wno-builtin-declaration-mismatch"
CFLAGS+=" -Werror -Wall -Wno-pointer-sign -Wno-sign-conversion -Wno-missing-braces -Wno-unused-value -Wno-builtin-declaration-mismatch -Wno-maybe-uninitialized"
export LDFLAGS="-lc_nonshared"
cd /usr/src/twemproxy
autoreconf -fvi
Expand Down
4 changes: 0 additions & 4 deletions contrib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
SUBDIRS = yaml-0.2.5

EXTRA_DIST = yaml-0.2.5.tar.gz

AM_CFLAGS =
AM_CFLAGS += -Wno-maybe-uninitialized
AM_CFLAGS += -Wno-pointer-sign -Wno-sign-conversion -Wno-unused-value -Wno-builtin-declaration-mismatch
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ AM_CFLAGS += -Wunused-function -Wunused-variable -Wunused-value
AM_CFLAGS += -Wno-unused-parameter -Wno-unused-value
AM_CFLAGS += -Wconversion -Wsign-compare
AM_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations
AM_CFLAGS += -Wno-format-zero-length

AM_LDFLAGS =
AM_LDFLAGS += -lm -lpthread -rdynamic
Expand Down
4 changes: 2 additions & 2 deletions src/nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ nc_get_options(int argc, char **argv, struct instance *nci)
}

if (value < NC_MBUF_MIN_SIZE || value > NC_MBUF_MAX_SIZE) {
log_stderr("nutcracker: mbuf chunk size must be between %zu and"
" %zu bytes", NC_MBUF_MIN_SIZE, NC_MBUF_MAX_SIZE);
log_stderr("nutcracker: mbuf chunk size must be between %d and"
" %d bytes", NC_MBUF_MIN_SIZE, NC_MBUF_MAX_SIZE);
return NC_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nc_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ conf_post_validate(struct conf *cf)

npool = array_n(&cf->pool);
if (npool == 0) {
log_error("conf: '%.*s' has no pools", cf->fname);
log_error("conf: '%s' has no pools", cf->fname);
return NC_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nc_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ conn_put(struct conn *conn)
void
conn_init(void)
{
log_debug(LOG_DEBUG, "conn size %d", sizeof(struct conn));
log_debug(LOG_DEBUG, "conn size %d", (int)sizeof(struct conn));
nfree_connq = 0;
TAILQ_INIT(&free_connq);
}
Expand Down
20 changes: 16 additions & 4 deletions src/nc_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ struct logger {
} \
} while (0)


#ifdef __GNUC__
# define NC_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#else
# define NC_GCC_VERSION 0
#endif
#if NC_GCC_VERSION >= 2007
#define NC_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
#else
#define NC_ATTRIBUTE_FORMAT(type, idx, first)
#endif

int log_init(int level, char *filename);
void log_deinit(void);
void log_level_up(void);
Expand All @@ -122,10 +134,10 @@ void log_level_set(int level);
void log_stacktrace(void);
void log_reopen(void);
int log_loggable(int level);
void _log(const char *file, int line, int panic, const char *fmt, ...);
void _log_stderr(const char *fmt, ...);
void _log_safe(const char *fmt, ...);
void _log_stderr_safe(const char *fmt, ...);
void _log(const char *file, int line, int panic, const char *fmt, ...) NC_ATTRIBUTE_FORMAT(printf, 4, 5);
void _log_stderr(const char *fmt, ...) NC_ATTRIBUTE_FORMAT(printf, 1, 2);
void _log_safe(const char *fmt, ...) NC_ATTRIBUTE_FORMAT(printf, 1, 2);
void _log_stderr_safe(const char *fmt, ...) NC_ATTRIBUTE_FORMAT(printf, 1, 2);
void _log_hexdump(const char *file, int line, char *data, int datalen, const char *fmt, ...);

#endif
12 changes: 7 additions & 5 deletions src/nc_mbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mbuf_free(struct mbuf *mbuf)
{
uint8_t *buf;

log_debug(LOG_VVERB, "put mbuf %p len %d", mbuf, mbuf->last - mbuf->pos);
log_debug(LOG_VVERB, "put mbuf %p len %d", mbuf, (int)(mbuf->last - mbuf->pos));

ASSERT(STAILQ_NEXT(mbuf, next) == NULL);
ASSERT(mbuf->magic == MBUF_MAGIC);
Expand All @@ -118,7 +118,7 @@ mbuf_free(struct mbuf *mbuf)
void
mbuf_put(struct mbuf *mbuf)
{
log_debug(LOG_VVERB, "put mbuf %p len %d", mbuf, mbuf->last - mbuf->pos);
log_debug(LOG_VVERB, "put mbuf %p len %d", mbuf, (int)(mbuf->last - mbuf->pos));

ASSERT(STAILQ_NEXT(mbuf, next) == NULL);
ASSERT(mbuf->magic == MBUF_MAGIC);
Expand Down Expand Up @@ -179,7 +179,8 @@ void
mbuf_insert(struct mhdr *mhdr, struct mbuf *mbuf)
{
STAILQ_INSERT_TAIL(mhdr, mbuf, next);
log_debug(LOG_VVERB, "insert mbuf %p len %d", mbuf, mbuf->last - mbuf->pos);
log_debug(LOG_VVERB, "insert mbuf %p len %d", mbuf,
(int)(mbuf->last - mbuf->pos));
}

/*
Expand All @@ -188,7 +189,8 @@ mbuf_insert(struct mhdr *mhdr, struct mbuf *mbuf)
void
mbuf_remove(struct mhdr *mhdr, struct mbuf *mbuf)
{
log_debug(LOG_VVERB, "remove mbuf %p len %d", mbuf, mbuf->last - mbuf->pos);
log_debug(LOG_VVERB, "remove mbuf %p len %d", mbuf,
(int)(mbuf->last - mbuf->pos));

STAILQ_REMOVE(mhdr, mbuf, mbuf, next);
STAILQ_NEXT(mbuf, next) = NULL;
Expand Down Expand Up @@ -269,7 +271,7 @@ mbuf_init(struct instance *nci)
mbuf_offset = mbuf_chunk_size - MBUF_HSIZE;

log_debug(LOG_DEBUG, "mbuf hsize %d chunk size %zu offset %zu length %zu",
MBUF_HSIZE, mbuf_chunk_size, mbuf_offset, mbuf_offset);
(int)MBUF_HSIZE, mbuf_chunk_size, mbuf_offset, mbuf_offset);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/nc_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ msg_dump(struct msg *msg, int level)
void
msg_init(void)
{
log_debug(LOG_DEBUG, "msg size %d", sizeof(struct msg));
log_debug(LOG_DEBUG, "msg size %d", (int)sizeof(struct msg));
msg_id = 0;
frag_id = 0;
nfree_msgq = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/nc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ server_failure(struct context *ctx, struct server *server)
next = now + pool->server_retry_timeout;

log_debug(LOG_INFO, "update pool %"PRIu32" '%.*s' to delete server '%.*s' "
"for next %"PRIu32" secs", pool->idx, pool->name.len,
"for next %"PRId64" secs", pool->idx, pool->name.len,
pool->name.data, server->pname.len, server->pname.data,
pool->server_retry_timeout / 1000 / 1000);

Expand Down
2 changes: 1 addition & 1 deletion src/nc_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ stats_send_rsp(struct stats *st)
return NC_ERROR;
}

log_debug(LOG_VERB, "send stats on sd %d %d bytes", sd, st->buf.len);
log_debug(LOG_VERB, "send stats on sd %d %zu bytes", sd, st->buf.len);

n = nc_sendn(sd, st->buf.data, st->buf.len);
if (n < 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/proto/nc_memcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ memcache_parse_req(struct msg *r)
log_error("parsed bad req %"PRIu64" of type %d with key "
"prefix '%.*s...' and length %d that exceeds "
"maximum key length", r->id, r->type, 16,
r->token, p - r->token);
r->token, (int)(p - r->token));
goto error;
} else if (keylen == 0) {
log_error("parsed bad req %"PRIu64" of type %d with an "
Expand Down Expand Up @@ -745,7 +745,7 @@ memcache_parse_req(struct msg *r)

log_hexdump(LOG_VERB, b->pos, mbuf_length(b), "parsed req %"PRIu64" res %d "
"type %d state %d rpos %d of %d", r->id, r->result, r->type,
r->state, r->pos - b->pos, b->last - b->pos);
r->state, (int)(r->pos - b->pos), (int)(b->last - b->pos));
return;

done:
Expand All @@ -757,7 +757,7 @@ memcache_parse_req(struct msg *r)

log_hexdump(LOG_VERB, b->pos, mbuf_length(b), "parsed req %"PRIu64" res %d "
"type %d state %d rpos %d of %d", r->id, r->result, r->type,
r->state, r->pos - b->pos, b->last - b->pos);
r->state, (int)(r->pos - b->pos), (int)(b->last - b->pos));
return;

enomem:
Expand Down Expand Up @@ -1205,7 +1205,7 @@ memcache_parse_rsp(struct msg *r)

log_hexdump(LOG_VERB, b->pos, mbuf_length(b), "parsed rsp %"PRIu64" res %d "
"type %d state %d rpos %d of %d", r->id, r->result, r->type,
r->state, r->pos - b->pos, b->last - b->pos);
r->state, (int)(r->pos - b->pos), (int)(b->last - b->pos));
return;

done:
Expand All @@ -1218,7 +1218,7 @@ memcache_parse_rsp(struct msg *r)

log_hexdump(LOG_VERB, b->pos, mbuf_length(b), "parsed rsp %"PRIu64" res %d "
"type %d state %d rpos %d of %d", r->id, r->result, r->type,
r->state, r->pos - b->pos, b->last - b->pos);
r->state, (int)(r->pos - b->pos), (int)(b->last - b->pos));
return;

error:
Expand Down

0 comments on commit 709de01

Please sign in to comment.