[systemd-devel] [PATCH] shared: fix cppcheck warnings

Boris Egorov egorov at linux.com
Tue Oct 14 07:50:10 PDT 2014


Minor patch. Fixes defects found by cppcheck: do not check if unsigned
value is const, reduce scope of a few variables.

Signed-off-by: Boris Egorov <egorov at linux.com>
---
 src/shared/macro.h | 2 +-
 src/shared/ring.c  | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/shared/macro.h b/src/shared/macro.h
index 9ee332c..372475b 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -295,7 +295,7 @@ static inline size_t IOVEC_INCREMENT(struct iovec
*i, unsigned n, size_t k) {
         for (j = 0; j < n; j++) {
                 size_t sub;
 -                if (_unlikely_(k <= 0))
+                if (_unlikely_(k == 0))
                         break;
                  sub = MIN(i[j].iov_len, k);
diff --git a/src/shared/ring.c b/src/shared/ring.c
index 309075e..211d698 100644
--- a/src/shared/ring.c
+++ b/src/shared/ring.c
@@ -83,8 +83,6 @@ size_t ring_peek(Ring *r, struct iovec *vec) {
  * return the number of bytes copied.
  */
 size_t ring_copy(Ring *r, void *buf, size_t size) {
-        size_t l;
-
         assert(r);
         assert(buf);
 @@ -92,6 +90,8 @@ size_t ring_copy(Ring *r, void *buf, size_t size) {
                 size = r->used;
          if (size > 0) {
+                size_t l;
+
                 l = r->size - r->start;
                 if (size <= l) {
                         memcpy(buf, &r->buf[r->start], size);
@@ -110,7 +110,6 @@ size_t ring_copy(Ring *r, void *buf, size_t size) {
  */
 static int ring_resize(Ring *r, size_t nsize) {
         uint8_t *buf;
-        size_t l;
          assert(r);
         assert(nsize > 0);
@@ -120,6 +119,8 @@ static int ring_resize(Ring *r, size_t nsize) {
                 return -ENOMEM;
          if (r->used > 0) {
+                size_t l;
+
                 l = r->size - r->start;
                 if (r->used <= l) {
                         memcpy(buf, &r->buf[r->start], r->used);
-- 
2.1.1



More information about the systemd-devel mailing list