aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-11-03 14:55:48 -0800
committerGarrett D'Amore <garrett@damore.org>2019-11-11 20:59:20 -0800
commit4b87eb768711cc6ed892d0d7b5afa9874b9f5c7b (patch)
tree5a3517d755166f09b53a565dcef81c13d5d2f23a /src/core
parent21b40e0b51c39a19574c1fe79a48872558189770 (diff)
downloadnng-4b87eb768711cc6ed892d0d7b5afa9874b9f5c7b.tar.gz
nng-4b87eb768711cc6ed892d0d7b5afa9874b9f5c7b.tar.bz2
nng-4b87eb768711cc6ed892d0d7b5afa9874b9f5c7b.zip
fixes #1004 Warning found by clang --analyze
It's possible for an empty chunk to have a NULL data pointer. Even when copying zero bytes, this makes clang somewhat unhappy.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/message.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/core/message.c b/src/core/message.c
index a054ac9e..58baa4b7 100644
--- a/src/core/message.c
+++ b/src/core/message.c
@@ -140,7 +140,9 @@ nni_chunk_grow(nni_chunk *ch, size_t newsz, size_t headwanted)
return (NNG_ENOMEM);
}
// Copy all the data, but not header or trailer.
- memcpy(newbuf + headwanted, ch->ch_ptr, ch->ch_len);
+ if (ch->ch_len > 0) {
+ memcpy(newbuf + headwanted, ch->ch_ptr, ch->ch_len);
+ }
nni_free(ch->ch_buf, ch->ch_cap);
ch->ch_buf = newbuf;
ch->ch_ptr = newbuf + headwanted;
@@ -221,7 +223,9 @@ nni_chunk_dup(nni_chunk *dst, const nni_chunk *src)
dst->ch_cap = src->ch_cap;
dst->ch_len = src->ch_len;
dst->ch_ptr = dst->ch_buf + (src->ch_ptr - src->ch_buf);
- memcpy(dst->ch_ptr, src->ch_ptr, dst->ch_len);
+ if (dst->ch_len > 0) {
+ memcpy(dst->ch_ptr, src->ch_ptr, dst->ch_len);
+ }
return (0);
}
@@ -278,7 +282,7 @@ nni_chunk_insert(nni_chunk *ch, const void *data, size_t len)
}
ch->ch_len += len;
- if (data) {
+ if (data != NULL) {
memcpy(ch->ch_ptr, data, len);
}
@@ -466,7 +470,9 @@ nni_msg_dup(nni_msg **dup, const nni_msg *src)
newmo->mo_val = ((char *) newmo + sizeof(*newmo));
newmo->mo_sz = mo->mo_sz;
newmo->mo_num = mo->mo_num;
- memcpy(newmo->mo_val, mo->mo_val, mo->mo_sz);
+ if (mo->mo_sz > 0) {
+ memcpy(newmo->mo_val, mo->mo_val, mo->mo_sz);
+ }
nni_list_append(&m->m_options, newmo);
}
m->m_pipe = src->m_pipe;
@@ -500,7 +506,7 @@ nni_msg_setopt(nni_msg *m, int opt, const void *val, size_t sz)
NNI_LIST_FOREACH (&m->m_options, oldmo) {
if (oldmo->mo_num == opt) {
- if (sz == oldmo->mo_sz) {
+ if (sz == oldmo->mo_sz && sz > 0) {
// nice! we can just overwrite old value
memcpy(oldmo->mo_val, val, sz);
return (0);
@@ -514,7 +520,9 @@ nni_msg_setopt(nni_msg *m, int opt, const void *val, size_t sz)
newmo->mo_val = ((char *) newmo + sizeof(*newmo));
newmo->mo_sz = sz;
newmo->mo_num = opt;
- memcpy(newmo->mo_val, val, sz);
+ if (sz > 0) {
+ memcpy(newmo->mo_val, val, sz);
+ }
if (oldmo != NULL) {
nni_list_remove(&m->m_options, oldmo);
nni_free(oldmo, sizeof(*oldmo) + oldmo->mo_sz);
@@ -533,7 +541,9 @@ nni_msg_getopt(nni_msg *m, int opt, void *val, size_t *szp)
size_t sz = *szp;
if (sz > mo->mo_sz) {
sz = mo->mo_sz;
- memcpy(val, mo->mo_val, sz);
+ if (sz > 0) {
+ memcpy(val, mo->mo_val, sz);
+ }
*szp = mo->mo_sz;
return (0);
}