Skip to content

Commit

Permalink
Merge pull request #319 from 00pauln00/Wextra_fixes
Browse files Browse the repository at this point in the history
Wextra fixes
  • Loading branch information
00pauln00 authored May 31, 2024
2 parents 94780f5 + 43ad064 commit 733263e
Show file tree
Hide file tree
Showing 48 changed files with 324 additions and 216 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AC_SUBST(MAJOR_VERSION, niova_core_major)
AC_SUBST(MINOR_VERSION, niova_core_minor)
AC_SUBST(VERSION_SUFFIX, niova_core_suffix)

AC_SUBST([AM_CFLAGS], ["-g -O2 -Wall"])
AC_SUBST([AM_CFLAGS], ["-g -O2 -Wall -Wextra"])
AC_SUBST([AM_CPPFLAGS], ["-Isrc/include -Isrc/contrib/include"])
AC_SUBST([AM_LDFLAGS], [" "])

Expand Down
8 changes: 4 additions & 4 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ buffer_set_navail_locked(const struct buffer_set *bs)

NIOVA_ASSERT(bs->bs_num_allocated >= 0);
NIOVA_ASSERT(bs->bs_num_pndg_alloc >= 0);
NIOVA_ASSERT(bs->bs_num_bufs >= (bs->bs_num_allocated +
bs->bs_num_pndg_alloc));
NIOVA_ASSERT((ssize_t)bs->bs_num_bufs >=
(bs->bs_num_allocated + bs->bs_num_pndg_alloc));

return bs->bs_num_bufs - (bs->bs_num_allocated + bs->bs_num_pndg_alloc);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ buffer_set_allocate_item_locked(struct buffer_set *bs)
bs->bs_num_allocated++;
bi->bi_allocated = true;

if (bs->bs_num_allocated > bs->bs_max_allocated)
if (bs->bs_num_allocated > (ssize_t)bs->bs_max_allocated)
bs->bs_max_allocated = bs->bs_num_allocated;

return bi;
Expand Down Expand Up @@ -262,7 +262,7 @@ buffer_set_release_pending_alloc(struct buffer_set *bs, const size_t nitems)

BS_LOCK(bs);

if (nitems > bs->bs_num_pndg_alloc)
if ((ssize_t)nitems > bs->bs_num_pndg_alloc)
{
BS_UNLOCK(bs);

Expand Down
6 changes: 3 additions & 3 deletions src/config_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ conf_token_set_parse_match_token(const char *input_buf, size_t input_buf_size,
continue;

// Check len prior to strncmp()
if (ct->ct_name_len + 1 > input_buf_size)
if ((ct->ct_name_len + 1U) > input_buf_size)
return NULL;

// The token string be immediately followed by a tab or space.
Expand All @@ -275,7 +275,7 @@ conf_token_value_check_and_clear_ws(const struct conf_token *ct,
if (!ct || !ctsp || !ctsp->ctsp_value_buf || !ctsp->ctsp_value_buf_size)
return -EINVAL;

const ssize_t original_value_str_len =
const size_t original_value_str_len =
strnlen(ctsp->ctsp_value_buf, ctsp->ctsp_value_buf_size);

if (original_value_str_len == ctsp->ctsp_value_buf_size)
Expand All @@ -288,7 +288,7 @@ conf_token_value_check_and_clear_ws(const struct conf_token *ct,
ctsp->ctsp_value_buf_size);

// Recheck the string len.
const ssize_t new_value_str_len =
const size_t new_value_str_len =
strnlen(ctsp->ctsp_value_buf, ctsp->ctsp_value_buf_size);

NIOVA_ASSERT(new_value_str_len <= original_value_str_len);
Expand Down
2 changes: 2 additions & 0 deletions src/ctl_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ lctli_epoll_mgr_cb(const struct epoll_handle *eph, uint32_t events)
{
NIOVA_ASSERT(eph);

(void)events;

struct ctl_interface *lctli = eph->eph_arg;

if (eph->eph_fd != lctli->lctli_inotify_fd)
Expand Down
12 changes: 6 additions & 6 deletions src/ctl_interface_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ctlic_request_done(struct ctlic_request *cr)
}

#define CTLIC_OUTPUT_TMP_FILE(tmp_str, file_name) \
const size_t CTLIC_OUTPUT_TMP_FILE_file_name_len = \
const ssize_t CTLIC_OUTPUT_TMP_FILE_file_name_len = \
NUM_HEX_CHARS(pid_t) + strnlen((file_name), PATH_MAX); \
if (CTLIC_OUTPUT_TMP_FILE_file_name_len >= PATH_MAX - 2) \
return -ENAMETOOLONG; \
Expand Down Expand Up @@ -690,7 +690,7 @@ ctlic_scan_registry_cb_output_writer(struct ctlic_iterator *citer)
struct ctlic_request *cr = citer->citer_cr;
const bool open_stanza = citer->citer_open_stanza;
const struct lreg_value *lv = &citer->citer_lv;
const size_t tab_depth = citer->citer_tab_depth;
const ssize_t tab_depth = citer->citer_tab_depth;
const size_t sibling_number = citer->citer_sibling_num;
const size_t starting_byte_cnt = citer->citer_starting_byte_cnt;
const char *value_string = ctlic_citer_2_value_string(citer);
Expand Down Expand Up @@ -1161,9 +1161,9 @@ ctlic_scan_registry_cb(struct lreg_node *lrn, void *arg, const int depth);
static bool
ctlic_scan_registry_cb_CT_ID_WHERE(struct lreg_node *lrn,
struct ctlic_iterator *parent_citer,
const int depth)
const unsigned int depth)
{
NIOVA_ASSERT(parent_citer && parent_citer->citer_cr && depth >= 0);
NIOVA_ASSERT(parent_citer && parent_citer->citer_cr && depth > 0);

struct ctlic_request *cr = parent_citer->citer_cr;
struct ctlic_matched_token *cmt = ctlic_get_current_matched_token(cr);
Expand Down Expand Up @@ -1233,9 +1233,9 @@ ctlic_scan_registry_cb_CT_ID_WHERE(struct lreg_node *lrn,
static bool
ctlic_scan_registry_cb_CT_ID_GET(struct lreg_node *lrn,
struct ctlic_iterator *parent_citer,
const int depth)
const unsigned int depth)
{
NIOVA_ASSERT(parent_citer && parent_citer->citer_cr && depth >= 0);
NIOVA_ASSERT(parent_citer && parent_citer->citer_cr && depth > 0);

struct ctlic_request *cr = parent_citer->citer_cr;
struct ctlic_matched_token *cmt = ctlic_get_current_matched_token(cr);
Expand Down
14 changes: 12 additions & 2 deletions src/ctl_svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ ctl_svc_node_token_hndlr_HOSTNAME(struct ctl_svc_node *csn,
const struct conf_token *ct,
const char *val_buf, size_t val_buf_sz)
{
(void)ct;
if (csn->csn_type == CTL_SVC_NODE_TYPE_RAFT)
return -EINVAL;

Expand Down Expand Up @@ -376,6 +377,8 @@ ctl_svc_node_token_hndlr_UUID(struct ctl_svc_node *csn,
const struct conf_token *ct,
const char *val_buf, size_t val_buf_sz)
{
(void)ct;

if (val_buf_sz > UUID_STR_LEN)
return -ENAMETOOLONG;

Expand Down Expand Up @@ -423,6 +426,8 @@ ctl_svc_node_token_hndlr_PEER(struct ctl_svc_node *csn,
const struct conf_token *ct,
const char *val_buf, size_t val_buf_sz)
{
(void)ct;

if (val_buf_sz > UUID_STR_LEN)
return -ENAMETOOLONG;

Expand All @@ -439,6 +444,8 @@ ctl_svc_node_token_hndlr_STORE(struct ctl_svc_node *csn,
const struct conf_token *ct,
const char *val_buf, size_t val_buf_sz)
{
(void)ct;

if (val_buf_sz > PATH_MAX)
return -ENAMETOOLONG;

Expand All @@ -465,6 +472,8 @@ ctl_svc_node_token_hndlr_IPADDR(struct ctl_svc_node *csn,
const struct conf_token *ct,
const char *val_buf, size_t val_buf_sz)
{
(void)ct;

if (val_buf_sz >= IPV4_STRLEN) // IPV4_STRLEN includes NULL terminator
return -ENAMETOOLONG;

Expand Down Expand Up @@ -679,7 +688,7 @@ ctl_svc_read_and_prep_conf_file(int ctl_svc_dir_fd, const char *input_file,
return read_rc;
}

const size_t null_cnt_end_of_buf =
const ssize_t null_cnt_end_of_buf =
niova_count_nulls_from_end_of_buffer(file_buf, read_rc);

NIOVA_ASSERT(read_rc >= null_cnt_end_of_buf);
Expand All @@ -693,7 +702,8 @@ ctl_svc_read_and_prep_conf_file(int ctl_svc_dir_fd, const char *input_file,
}

// Workaround for files which do not have a newline at the end.
if (read_rc && file_buf[read_rc - 1] != '\n' && read_rc < file_buf_sz)
if (read_rc && file_buf[read_rc - 1] != '\n' &&
read_rc < (ssize_t)file_buf_sz)
{
file_buf[read_rc] = '\n';
read_rc += 1;
Expand Down
4 changes: 3 additions & 1 deletion src/epoll_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ REGISTRY_ENTRY_FILE_GENERATE;

typedef int epoll_mgr_thread_ctx_int_t;

static size_t epollMgrNumEvents = EPOLL_MGR_DEF_EVENTS;
static long long epollMgrNumEvents = EPOLL_MGR_DEF_EVENTS;
static pthread_mutex_t epollMgrInstallLock = PTHREAD_MUTEX_INITIALIZER;

static void
epoll_mgr_wake_cb(const struct epoll_handle *eph, uint32_t evs)
{
(void)evs;

uint64_t eventcnt;
int rc = read(eph->eph_fd, &eventcnt, sizeof(eventcnt));
SIMPLE_LOG_MSG(LL_TRACE, "read(): rc=%d evcnt=%lu", rc, eventcnt);
Expand Down
2 changes: 1 addition & 1 deletion src/ev_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ev_pipe_notify(struct ev_pipe *evp)

int rc = 0;

int64_t old_write_cnt = niova_atomic_read(&evp->evp_writer_cnt);
uint64_t old_write_cnt = niova_atomic_read(&evp->evp_writer_cnt);

if (old_write_cnt < evp->evp_reader_cnt)
{
Expand Down
4 changes: 2 additions & 2 deletions src/fault_inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fault_inject_set_lreg_install(struct fault_injection_set *fis)
NIOVA_ASSERT(fis);
SIMPLE_LOG_MSG(LL_DEBUG, "size=%zu", fis->finj_set_size);

for (int i = 0; i < fis->finj_set_size; i++)
for (size_t i = 0; i < fis->finj_set_size; i++)
{
struct lreg_node *lrn = &fis->finj_set[i].flti_lrn;

Expand Down Expand Up @@ -336,7 +336,7 @@ fault_inject_set_install(struct fault_injection *finj_set, size_t set_size,
{
struct fault_injection_set *fis = &faultInjectionSets[idx];

for (int i = 0; i < fis->finj_set_size; i++)
for (size_t i = 0; i < fis->finj_set_size; i++)
{
struct lreg_node *lrn = &fis->finj_set[i].flti_lrn;

Expand Down
11 changes: 6 additions & 5 deletions src/file_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ file_util_open_and_read(int dirfd, const char *file_name, char *output_buf,
else if (!S_ISREG(stb.st_mode))
return -ENOTSUP;

else if (!proc_file && stb.st_size > output_size)
else if (!proc_file && (size_t)stb.st_size > output_size)
return -E2BIG;

else if (!proc_file && !stb.st_size) // nothing to read
Expand All @@ -67,8 +67,9 @@ file_util_open_and_read(int dirfd, const char *file_name, char *output_buf,

bool close_fd = ret_fd ? false : true;

ssize_t io_rc = niova_io_read(fd, output_buf,
proc_file ? output_size : stb.st_size);
ssize_t io_rc =
niova_io_read(fd, output_buf,
proc_file ? output_size : (size_t)stb.st_size);
if (io_rc < 0)
{
io_rc = -errno;
Expand All @@ -80,7 +81,7 @@ file_util_open_and_read(int dirfd, const char *file_name, char *output_buf,
close_fd = true;
}
else if ((!proc_file && io_rc != stb.st_size) ||
(proc_file && io_rc == output_size))
(proc_file && io_rc == (ssize_t)output_size))
{
io_rc = -EMSGSIZE;
close_fd = true;
Expand All @@ -90,7 +91,7 @@ file_util_open_and_read(int dirfd, const char *file_name, char *output_buf,
*ret_fd = fd;
}

if (io_rc > 0 && io_rc < output_size)
if (io_rc > 0 && io_rc < (ssize_t)output_size)
output_buf[io_rc] = '\0'; // terminate the output buffer

if (close_fd)
Expand Down
19 changes: 11 additions & 8 deletions src/include/binary_hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

struct binary_hist
{
const int bh_start_bit;
const int bh_num_buckets;
size_t bh_values[BIN_HIST_BUCKETS_MAX];
const unsigned int bh_start_bit;
const unsigned int bh_num_buckets;
size_t bh_values[BIN_HIST_BUCKETS_MAX];
};

static inline int
Expand All @@ -42,11 +42,14 @@ binary_hist_init(struct binary_hist *bh, int start_bit, int num_buckets)
static inline int
binary_hist_size(const struct binary_hist *bh)
{
if (!bh)
return -EINVAL;

return bh->bh_num_buckets;
}

static inline long long
binary_hist_get_cnt(const struct binary_hist *bh, int pos)
binary_hist_get_cnt(const struct binary_hist *bh, unsigned int pos)
{
if (!bh || pos >= bh->bh_num_buckets || pos >= BIN_HIST_BUCKETS_MAX)
return -EINVAL;
Expand Down Expand Up @@ -107,7 +110,7 @@ binary_hist_incorporate_val_multi(struct binary_hist *bh,
}

static inline long long
binary_hist_lower_bucket_range(const struct binary_hist *bh, int pos)
binary_hist_lower_bucket_range(const struct binary_hist *bh, unsigned int pos)
{
if (!bh || pos >= bh->bh_num_buckets)
return -EINVAL;
Expand All @@ -117,13 +120,13 @@ binary_hist_lower_bucket_range(const struct binary_hist *bh, int pos)
}

static inline long long
binary_hist_upper_bucket_range(const struct binary_hist *bh, int pos)
binary_hist_upper_bucket_range(const struct binary_hist *bh, unsigned int pos)
{
if (!bh || pos >= bh->bh_num_buckets)
return -EINVAL;

return pos == bh->bh_num_buckets - 1 ?
-1 : (unsigned long long)((1ULL << (pos + bh->bh_start_bit)) - 1);
-1LL : (long long)((1ULL << (pos + bh->bh_start_bit)) - 1);
}

static inline void
Expand All @@ -142,7 +145,7 @@ binary_hist_print(const struct binary_hist *bh, size_t num_hist,
fprintf(stdout, "\thist-%zu = {", i);

const struct binary_hist *b = &bh[i];
for (int j = 0; j < b->bh_num_buckets; j++)
for (unsigned int j = 0; j < b->bh_num_buckets; j++)
{
if (binary_hist_get_cnt(b, j))
{
Expand Down
4 changes: 2 additions & 2 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SLIST_HEAD(buffer_user_slist, buffer_item);
struct buffer_set
{
char bs_name[BUFFER_SET_NAME_MAX + 1];
ssize_t bs_num_bufs;
size_t bs_num_bufs;
ssize_t bs_num_allocated;
ssize_t bs_num_user_cached;
ssize_t bs_num_pndg_alloc;
Expand Down Expand Up @@ -79,7 +79,7 @@ buffer_item_touch(struct buffer_item *bi)

char *x = (char *)bi->bi_iov.iov_base;

for (off_t off = 0; off < bi->bi_iov.iov_len; off += buffer_page_size())
for (size_t off = 0; off < bi->bi_iov.iov_len; off += buffer_page_size())
x[off] = 0xff;
}

Expand Down
4 changes: 2 additions & 2 deletions src/include/ctl_svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ ctl_svc_node_raft_2_num_members(const struct ctl_svc_node *csn)
csn->csn_raft.csnr_num_members : RAFT_PEER_ANY;
}

static inline const uint16_t
static inline uint16_t
ctl_svc_node_peer_2_port(const struct ctl_svc_node *csn)
{
return (csn && ctl_svc_node_is_peer(csn)) ?
csn->csn_peer.csnp_port : 0;
}

static inline const uint16_t
static inline uint16_t
ctl_svc_node_peer_2_client_port(const struct ctl_svc_node *csn)
{
return (csn && ctl_svc_node_is_peer(csn)) ?
Expand Down
3 changes: 2 additions & 1 deletion src/include/pumice_db_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pmdb_request_options_init(pmdb_request_opts_t *pmdb_req, int use_user_buffer,
size_t get_buffer_size,
int timeout_sec)
{
(void)use_user_buffer;
pmdb_req->pro_non_blocking = non_blocking;
pmdb_req->pro_get_response = get_response;
pmdb_req->pro_stat = obj_stat;
Expand Down Expand Up @@ -225,6 +226,6 @@ pmdb_direct_msg_init(struct pmdb_msg *msg, pmdb_obj_id_t *obj,
if (op == pmdb_op_write)
msg->pmdbrm_write_seqno = sequence_num;
}


#endif
5 changes: 4 additions & 1 deletion src/include/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@

#define RAFT_HEARTBEAT_FREQ_PER_ELECTION 10

#define RAFT_ENTRY_IDX_ANY -1LL
#define RAFT_TERM_ANY -1LL

#define RAFT_MIN_APPEND_ENTRY_IDX -1

#define RAFT_INSTANCE_2_SELF_UUID(ri) \
Expand Down Expand Up @@ -216,7 +219,7 @@ struct raft_recovery_handle
int64_t rrh_peer_chkpt_idx;
ssize_t rrh_chkpt_size;
ssize_t rrh_remaining;
ssize_t rrh_completed;
size_t rrh_completed;
char rrh_rate_bytes_per_sec[BW_RATE_LEN + 1];
struct timespec rrh_start;
bool rrh_from_recovery_marker;
Expand Down
Loading

0 comments on commit 733263e

Please sign in to comment.