qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl


From: Purcareata Bogdan
Subject: Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl
Date: Mon, 6 Apr 2015 10:15:16 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 03.04.2015 17:44, Michael Tokarev wrote:
03.04.2015 17:15, Paolo Bonzini wrote:
On 03/04/2015 13:01, Bogdan Purcareata wrote:
...
-    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / (size_t)BDRV_SECTOR_SIZE) < 0) {
+    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0)) 
{
          int serrno = errno;

Hmm..  I don't think this is right at all.  Now we compare size_t with zero,
the result is always false, and set error if ioctl return anything other than 0,
including any positive value.

Compare:

   if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0))
   if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE)) < 0)

I think the latter is the right version.

Yes, the latter is indeed the right version. Great catch!

So much for trivial... ;)

Me and my slippery fingers. Sorry for the mishap.

Bogdan P.

Thanks,

/mjt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]