summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-04-24 16:39:35 -0700
committerGarrett D'Amore <garrett@damore.org>2018-04-24 16:39:35 -0700
commitd35973833e6bf05fec29100a4d5e66bb07b06659 (patch)
treeb380e99a092a0229c8f087d231306b398f6f43f2 /src/core
parent007f74b1053c9406340ffa728f9c254ba37e2a6c (diff)
downloadnng-d35973833e6bf05fec29100a4d5e66bb07b06659.tar.gz
nng-d35973833e6bf05fec29100a4d5e66bb07b06659.tar.bz2
nng-d35973833e6bf05fec29100a4d5e66bb07b06659.zip
fix a number of cppcheck complaints (not all)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/message.c12
-rw-r--r--src/core/msgqueue.c23
-rw-r--r--src/core/panic.c13
-rw-r--r--src/core/random.c10
-rw-r--r--src/core/socket.c1
-rw-r--r--src/core/taskq.c26
-rw-r--r--src/core/timer.c5
7 files changed, 38 insertions, 52 deletions
diff --git a/src/core/message.c b/src/core/message.c
index 35153f01..5c396f21 100644
--- a/src/core/message.c
+++ b/src/core/message.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -102,7 +102,6 @@ nni_msg_dump(const char *banner, const nni_msg *msg)
static int
nni_chunk_grow(nni_chunk *ch, size_t newsz, size_t headwanted)
{
- size_t headroom = 0;
uint8_t *newbuf;
// We assume that if the pointer is a valid pointer, and inside
@@ -121,7 +120,7 @@ nni_chunk_grow(nni_chunk *ch, size_t newsz, size_t headwanted)
if ((ch->ch_ptr >= ch->ch_buf) &&
(ch->ch_ptr < (ch->ch_buf + ch->ch_cap))) {
- headroom = (size_t)(ch->ch_ptr - ch->ch_buf);
+ size_t headroom = (size_t)(ch->ch_ptr - ch->ch_buf);
if (headwanted < headroom) {
headwanted = headroom; // Never shrink this.
}
@@ -474,10 +473,9 @@ nni_msg_getopt(nni_msg *m, int opt, void *val, size_t *szp)
int
nni_msg_realloc(nni_msg *m, size_t sz)
{
- int rv = 0;
-
if (m->m_body.ch_len < sz) {
- rv = nni_chunk_append(&m->m_body, NULL, sz - m->m_body.ch_len);
+ int rv =
+ nni_chunk_append(&m->m_body, NULL, sz - m->m_body.ch_len);
if (rv != 0) {
return (rv);
}
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c
index a4a7ff36..2367b57f 100644
--- a/src/core/msgqueue.c
+++ b/src/core/msgqueue.c
@@ -82,8 +82,6 @@ nni_msgq_init(nni_msgq **mqp, unsigned cap)
void
nni_msgq_fini(nni_msgq *mq)
{
- nni_msg *msg;
-
if (mq == NULL) {
return;
}
@@ -91,7 +89,7 @@ nni_msgq_fini(nni_msgq *mq)
/* Free any orphaned messages. */
while (mq->mq_len > 0) {
- msg = mq->mq_msgs[mq->mq_get];
+ nni_msg *msg = mq->mq_msgs[mq->mq_get];
mq->mq_get++;
if (mq->mq_get >= mq->mq_alloc) {
mq->mq_get = 0;
@@ -114,8 +112,6 @@ nni_msgq_fini(nni_msgq *mq)
void
nni_msgq_set_get_error(nni_msgq *mq, int error)
{
- nni_aio *aio;
-
// Let all pending blockers know we are closing the queue.
nni_mtx_lock(&mq->mq_lock);
if (mq->mq_closed) {
@@ -123,6 +119,7 @@ nni_msgq_set_get_error(nni_msgq *mq, int error)
error = NNG_ECLOSED;
}
if (error != 0) {
+ nni_aio *aio;
while ((aio = nni_list_first(&mq->mq_aio_getq)) != NULL) {
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, error);
@@ -136,8 +133,6 @@ nni_msgq_set_get_error(nni_msgq *mq, int error)
void
nni_msgq_set_put_error(nni_msgq *mq, int error)
{
- nni_aio *aio;
-
// Let all pending blockers know we are closing the queue.
nni_mtx_lock(&mq->mq_lock);
if (mq->mq_closed) {
@@ -145,6 +140,7 @@ nni_msgq_set_put_error(nni_msgq *mq, int error)
error = NNG_ECLOSED;
}
if (error != 0) {
+ nni_aio *aio;
while ((aio = nni_list_first(&mq->mq_aio_putq)) != NULL) {
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, error);
@@ -158,8 +154,6 @@ nni_msgq_set_put_error(nni_msgq *mq, int error)
void
nni_msgq_set_error(nni_msgq *mq, int error)
{
- nni_aio *aio;
-
// Let all pending blockers know we are closing the queue.
nni_mtx_lock(&mq->mq_lock);
if (mq->mq_closed) {
@@ -167,6 +161,7 @@ nni_msgq_set_error(nni_msgq *mq, int error)
error = NNG_ECLOSED;
}
if (error != 0) {
+ nni_aio *aio;
while (((aio = nni_list_first(&mq->mq_aio_getq)) != NULL) ||
((aio = nni_list_first(&mq->mq_aio_putq)) != NULL)) {
nni_aio_list_remove(aio);
@@ -207,13 +202,11 @@ static void
nni_msgq_run_putq(nni_msgq *mq)
{
nni_aio *waio;
- nni_aio *raio;
- nni_msg *msg;
- size_t len;
while ((waio = nni_list_first(&mq->mq_aio_putq)) != NULL) {
- msg = nni_aio_get_msg(waio);
- len = nni_msg_len(msg);
+ nni_msg *msg = nni_aio_get_msg(waio);
+ size_t len = nni_msg_len(msg);
+ nni_aio *raio;
// The presence of any blocked reader indicates that
// the queue is empty, otherwise it would have just taken
@@ -257,9 +250,9 @@ static void
nni_msgq_run_getq(nni_msgq *mq)
{
nni_aio *raio;
- nni_aio *waio;
while ((raio = nni_list_first(&mq->mq_aio_getq)) != NULL) {
+ nni_aio *waio;
// If anything is waiting in the queue, get it first.
if (mq->mq_len != 0) {
nni_msg *msg = mq->mq_msgs[mq->mq_get++];
diff --git a/src/core/panic.c b/src/core/panic.c
index f3c7cb26..ff621a59 100644
--- a/src/core/panic.c
+++ b/src/core/panic.c
@@ -1,5 +1,6 @@
//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -23,18 +24,16 @@ void
nni_show_backtrace(void)
{
#if NNG_HAVE_BACKTRACE
- void * frames[50];
- int nframes;
- char **lines;
- int i;
+ void *frames[50];
+ int nframes;
nframes = backtrace(frames, sizeof(frames) / sizeof(frames[0]));
if (nframes > 1) {
- lines = backtrace_symbols(frames, nframes);
+ char **lines = backtrace_symbols(frames, nframes);
if (lines == NULL) {
return;
}
- for (i = 1; i < nframes; i++) {
+ for (int i = 1; i < nframes; i++) {
nni_println(lines[i]);
}
}
diff --git a/src/core/random.c b/src/core/random.c
index febd0848..2d899f21 100644
--- a/src/core/random.c
+++ b/src/core/random.c
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -37,13 +38,12 @@ typedef struct {
static void
nni_isaac(nni_isaac_ctx *ctx)
{
- register uint32_t i, x, y;
-
ctx->cc++; // cc incremented once per 256 results
ctx->bb += ctx->cc; // then combined with bb
- for (i = 0; i < 256; ++i) {
- x = ctx->mm[i];
+ for (uint32_t i = 0; i < 256; ++i) {
+ uint32_t x = ctx->mm[i];
+ uint32_t y;
switch (i % 4) {
case 0:
ctx->aa ^= (ctx->aa << 13);
diff --git a/src/core/socket.c b/src/core/socket.c
index 8a14beb5..5a581cd3 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -81,7 +81,6 @@ struct nni_socket {
nni_list s_pipes; // active pipes
nni_list s_ctxs; // active contexts (protected by global nni_sock_lk)
- int s_ep_pend; // EP dial/listen in progress
int s_closing; // Socket is closing
int s_closed; // Socket closed, protected by global lock
bool s_ctxwait; // Waiting for contexts to close.
diff --git a/src/core/taskq.c b/src/core/taskq.c
index 90cf7e22..b0fe160b 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -70,9 +70,7 @@ nni_taskq_thread(void *self)
int
nni_taskq_init(nni_taskq **tqp, int nthr)
{
- int rv;
nni_taskq *tq;
- int i;
if ((tq = NNI_ALLOC_STRUCT(tq)) == NULL) {
return (NNG_ENOMEM);
@@ -89,7 +87,8 @@ nni_taskq_init(nni_taskq **tqp, int nthr)
nni_cv_init(&tq->tq_sched_cv, &tq->tq_mtx);
nni_cv_init(&tq->tq_wait_cv, &tq->tq_mtx);
- for (i = 0; i < nthr; i++) {
+ for (int i = 0; i < nthr; i++) {
+ int rv;
tq->tq_threads[i].tqt_tq = tq;
tq->tq_threads[i].tqt_running = NULL;
rv = nni_thr_init(&tq->tq_threads[i].tqt_thread,
@@ -100,7 +99,7 @@ nni_taskq_init(nni_taskq **tqp, int nthr)
}
}
tq->tq_run = 1;
- for (i = 0; i < tq->tq_nthreads; i++) {
+ for (int i = 0; i < tq->tq_nthreads; i++) {
nni_thr_run(&tq->tq_threads[i].tqt_thread);
}
*tqp = tq;
@@ -190,20 +189,19 @@ void
nni_task_wait(nni_task *task)
{
nni_taskq *tq = task->task_tq;
- int running;
if (task->task_cb == NULL) {
return;
}
nni_mtx_lock(&tq->tq_mtx);
for (;;) {
- running = 0;
+ bool running = false;
if (nni_list_active(&tq->tq_tasks, task)) {
- running = 1;
+ running = true;
} else {
for (int i = 0; i < tq->tq_nthreads; i++) {
if (tq->tq_threads[i].tqt_running == task) {
- running = 1;
+ running = true;
break;
}
}
@@ -222,15 +220,15 @@ int
nni_task_cancel(nni_task *task)
{
nni_taskq *tq = task->task_tq;
- int running;
+ bool running;
nni_mtx_lock(&tq->tq_mtx);
- running = 1;
+ running = true;
for (;;) {
- running = 0;
+ running = false;
for (int i = 0; i < tq->tq_nthreads; i++) {
if (tq->tq_threads[i].tqt_running == task) {
- running = 1;
+ running = true;
break;
}
}
diff --git a/src/core/timer.c b/src/core/timer.c
index 08337b70..ad47ae33 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -103,8 +103,7 @@ nni_timer_cancel(nni_timer_node *node)
void
nni_timer_schedule(nni_timer_node *node, nni_time when)
{
- nni_timer * timer = &nni_global_timer;
- nni_timer_node *srch;
+ nni_timer *timer = &nni_global_timer;
nni_mtx_lock(&timer->t_mx);
node->t_expire = when;
@@ -114,7 +113,7 @@ nni_timer_schedule(nni_timer_node *node, nni_time when)
}
if (when != NNI_TIME_NEVER) {
- srch = nni_list_first(&timer->t_entries);
+ nni_timer_node *srch = nni_list_first(&timer->t_entries);
while ((srch != NULL) && (srch->t_expire < node->t_expire)) {
srch = nni_list_next(&timer->t_entries, srch);
}