Patchwork [1/2] sheepdog: correct signedness of comparison

login
register
mail settings
Submitter namei.unix@gmail.com
Date July 25, 2013, 5:25 a.m.
Message ID <1374729935-27667-2-git-send-email-namei.unix@gmail.com>
Download mbox | patch
Permalink /patch/261588/
State New
Headers show

Comments

namei.unix@gmail.com - July 25, 2013, 5:25 a.m.
When signed int compared to unsigned int, signed int will be converted to
unsigned int.

For example, (-1 < sizeof(structure)) always true because -1 in the left is
converted into unsigned int, thus this restule in unexpected true.

Signed-off-by: Liu Yuan <namei.unix@gmail.com>
---
 block/sheepdog.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Patch

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 58e03c8..8c6c8f1 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -616,7 +616,7 @@  static coroutine_fn void do_co_req(void *opaque)
 
     if (*rlen) {
         ret = qemu_co_recv(sockfd, data, *rlen);
-        if (ret < *rlen) {
+        if (ret < (int)*rlen) {
             error_report("failed to get the data, %s", strerror(errno));
             ret = -errno;
             goto out;
@@ -755,7 +755,7 @@  static void coroutine_fn aio_read_response(void *opaque)
 
     /* read a header */
     ret = qemu_co_recv(fd, &rsp, sizeof(rsp));
-    if (ret < sizeof(rsp)) {
+    if (ret < (int)sizeof(rsp)) {
         error_report("failed to get the header, %s", strerror(errno));
         goto err;
     }
@@ -806,7 +806,7 @@  static void coroutine_fn aio_read_response(void *opaque)
     case AIOCB_READ_UDATA:
         ret = qemu_co_recvv(fd, acb->qiov->iov, acb->qiov->niov,
                             aio_req->iov_offset, rsp.data_length);
-        if (ret < rsp.data_length) {
+        if (ret < (int)rsp.data_length) {
             error_report("failed to get the data, %s", strerror(errno));
             goto err;
         }
@@ -1116,7 +1116,7 @@  static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
 {
     int nr_copies = s->inode.nr_copies;
     SheepdogObjReq hdr;
-    unsigned int wlen = 0;
+    int wlen = 0;
     int ret;
     uint64_t oid = aio_req->oid;
     unsigned int datalen = aio_req->data_len;
@@ -1173,7 +1173,7 @@  static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
 
     /* send a header */
     ret = qemu_co_send(s->fd, &hdr, sizeof(hdr));
-    if (ret < sizeof(hdr)) {
+    if (ret < (int)sizeof(hdr)) {
         error_report("failed to send a req, %s", strerror(errno));
         goto out;
     }