Add -Wall -Werror and friends

Update the configure to add some sanity -W arguments.
A good start is probably :
  -Wall -Werror -Wshadow -Wno-write-strings -Wstrict-prototypes
  -Wpointer-arith -Wcast-align -Wno-strict-aliasing

Fixup the paces in the code that triggers.
(one of which is readahead code which is perhaps broken?)

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2015-03-10 21:06:38 -07:00
parent e775160243
commit 84607f4821
11 changed files with 42 additions and 23 deletions

View File

@ -1,4 +1,5 @@
SUBDIRS = doc mount nfs nlm nsm portmap rquota lib include utils . $(MAYBE_EXAMPLES)
ACLOCAL_AMFLAGS = -I m4
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnfs.pc

View File

@ -1,8 +1,11 @@
AC_PREREQ(2.50)
AC_INIT([libnfs], [1.9.7], [ronniesahlberg@gmail.com])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
m4_pattern_allow([AM_PROG_AR])
AM_PROG_AR
# Work around stupid autoconf default cflags. pt 1
SAVE_CFLAGS="x${CFLAGS}"
@ -67,6 +70,17 @@ fi
AC_SUBST(MAYBE_EXAMPLES)
AC_ARG_ENABLE([werror], [AS_HELP_STRING([--disable-werror],
[Disables building with -Werror by default])])
if test "$ac_cv_prog_gcc" = yes; then
WARN_CFLAGS="-Wall -Werror -Wshadow -Wno-write-strings -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wno-strict-aliasing"
if test "x$enable_werror" != "xno"; then
WARN_CFLAGS="$WARN_CFLAGS -Werror"
fi
fi
AC_SUBST(WARN_CFLAGS)
case $host in
*solaris*)

View File

@ -147,9 +147,9 @@ void rpc_free_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu);
int rpc_queue_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu);
int rpc_get_pdu_size(char *buf);
int rpc_process_pdu(struct rpc_context *rpc, char *buf, int size);
void rpc_error_all_pdus(struct rpc_context *rpc, char *error);
void rpc_error_all_pdus(struct rpc_context *rpc, const char *error);
void rpc_set_error(struct rpc_context *rpc, char *error_string, ...)
void rpc_set_error(struct rpc_context *rpc, const char *error_string, ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif

View File

@ -115,7 +115,7 @@ int rpc_connect_program_async(struct rpc_context *rpc, const char *server, int p
* When disconnecting a connection in flight. All commands in flight will be called with the callback
* and status RPC_STATUS_ERROR. Data will be the error string for the disconnection.
*/
int rpc_disconnect(struct rpc_context *rpc, char *error);
int rpc_disconnect(struct rpc_context *rpc, const char *error);
/*

View File

@ -278,7 +278,7 @@ bool_t libnfs_zdr_replymsg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *m
struct AUTH *libnfs_authnone_create(void);
#define authunix_create libnfs_authunix_create
struct AUTH *libnfs_authunix_create(char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups);
struct AUTH *libnfs_authunix_create(const char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups);
#define authunix_create_default libnfs_authunix_create_default
struct AUTH *libnfs_authunix_create_default(void);

View File

@ -1,3 +1,5 @@
AM_CFLAGS=$(WARN_CFLAGS)
lib_LTLIBRARIES = libnfs.la
libnfs_la_CPPFLAGS = -I$(abs_top_srcdir)/include \

View File

@ -76,7 +76,7 @@ struct rpc_context *rpc_init_context(void)
free(rpc);
return NULL;
}
rpc->xid = salt + time(NULL) + getpid() << 16;
rpc->xid = salt + time(NULL) + (getpid() << 16);
salt += 0x01000000;
rpc->fd = -1;
rpc->tcp_syncnt = RPC_PARAM_UNDEFINED;
@ -142,7 +142,7 @@ void rpc_set_gid(struct rpc_context *rpc, int gid) {
rpc_set_uid_gid(rpc, rpc->uid, gid);
}
void rpc_set_error(struct rpc_context *rpc, char *error_string, ...)
void rpc_set_error(struct rpc_context *rpc, const char *error_string, ...)
{
va_list ap;
char *old_error_string = rpc->error_string;
@ -166,15 +166,15 @@ char *rpc_get_error(struct rpc_context *rpc)
return rpc->error_string;
}
void rpc_error_all_pdus(struct rpc_context *rpc, char *error)
void rpc_error_all_pdus(struct rpc_context *rpc, const char *error)
{
struct rpc_pdu *pdu, *next;
struct rpc_pdu *pdu;
unsigned int i;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
while ((pdu = rpc->outqueue.head) != NULL) {
pdu->cb(rpc, RPC_STATUS_ERROR, error, pdu->private_data);
pdu->cb(rpc, RPC_STATUS_ERROR, (void *)error, pdu->private_data);
rpc->outqueue.head = pdu->next;
rpc_free_pdu(rpc, pdu);
}
@ -184,7 +184,8 @@ void rpc_error_all_pdus(struct rpc_context *rpc, char *error)
struct rpc_queue *q = &rpc->waitpdu[i];
while((pdu = q->head) != NULL) {
pdu->cb(rpc, RPC_STATUS_ERROR, error, pdu->private_data);
pdu->cb(rpc, RPC_STATUS_ERROR, (void *)error,
pdu->private_data);
q->head = pdu->next;
rpc_free_pdu(rpc, pdu);
}

View File

@ -1463,12 +1463,12 @@ struct exportnode *mount_getexports(const char *server)
return cb_data.return_data;
}
void mount_free_export_list(struct exportnode *exports)
void mount_free_export_list(struct exportnode *exp)
{
struct exportnode *tmp;
while ((tmp = exports)) {
exports = exports->ex_next;
while ((tmp = exp)) {
exp = exp->ex_next;
free(tmp->ex_dir);
free(tmp);
}

View File

@ -516,7 +516,7 @@ struct AUTH *authnone_create(void)
return auth;
}
struct AUTH *libnfs_authunix_create(char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups)
struct AUTH *libnfs_authunix_create(const char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups)
{
struct AUTH *auth;
int size;

View File

@ -104,7 +104,7 @@ struct nfs_readahead {
uint64_t buf_offset;
uint64_t buf_count;
time_t buf_ts;
void *buf;
char *buf;
uint32_t cur_ra;
};
@ -251,7 +251,7 @@ char *nfs_get_error(struct nfs_context *nfs)
return rpc_get_error(nfs->rpc);
};
static int nfs_set_context_args(struct nfs_context *nfs, char *arg, char *val)
static int nfs_set_context_args(struct nfs_context *nfs, const char *arg, const char *val)
{
if (!strcmp(arg, "tcp-syncnt")) {
rpc_set_tcp_syncnt(nfs_get_rpc_context(nfs), atoi(val));
@ -560,7 +560,7 @@ static void rpc_connect_program_3_cb(struct rpc_context *rpc, int status, void *
struct rpc_cb_data *data = private_data;
struct pmap3_string_result *gar;
uint32_t rpc_port = 0;
unsigned char *ptr;
char *ptr;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
@ -1346,7 +1346,7 @@ static int nfs_lookup_path_async_internal(struct nfs_context *nfs, fattr3 *attr,
slash = strchr(path, '/');
if (attr && attr->type == NF3LNK && (!data->no_follow || *path != '\0')) {
READLINK3args args;
READLINK3args rl_args;
if (data->link_count++ >= MAX_LINK_COUNT) {
data->cb(-ELOOP, nfs, "Too many levels of symbolic links", data->private_data);
@ -1354,9 +1354,9 @@ static int nfs_lookup_path_async_internal(struct nfs_context *nfs, fattr3 *attr,
return -1;
}
args.symlink = *fh;
rl_args.symlink = *fh;
if (rpc_nfs3_readlink_async(nfs->rpc, nfs_lookup_path_2_cb, &args, data) != 0) {
if (rpc_nfs3_readlink_async(nfs->rpc, nfs_lookup_path_2_cb, &rl_args, data) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send READLINK call for %s", data->path);
data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
free_nfs_cb_data(data);
@ -2225,6 +2225,7 @@ static void nfs_pread_mcb(struct rpc_context *rpc, int status, void *command_dat
cb_err = data->max_offset - data->org_offset;
cb_data = data->buffer + (data->org_offset - data->offset);
} else {
res = command_data;
cb_err = res->READ3res_u.resok.count;
cb_data = res->READ3res_u.resok.data.data_val;
}

View File

@ -273,7 +273,7 @@ static int rpc_read_from_socket(struct rpc_context *rpc)
pdu_size = rpc_get_pdu_size(rpc->inbuf);
if (rpc->insize < pdu_size) {
unsigned char *buf;
char *buf;
buf = malloc(pdu_size);
if (buf == NULL) {
@ -592,7 +592,7 @@ int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc
return 0;
}
int rpc_disconnect(struct rpc_context *rpc, char *error)
int rpc_disconnect(struct rpc_context *rpc, const char *error)
{
assert(rpc->magic == RPC_CONTEXT_MAGIC);