From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ye2py-0004O4-Jx for qemu-devel@nongnu.org; Fri, 03 Apr 2015 10:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ye2pu-000568-9s for qemu-devel@nongnu.org; Fri, 03 Apr 2015 10:44:46 -0400 Message-ID: <551EA74F.5030906@msgid.tls.msk.ru> Date: Fri, 03 Apr 2015 17:44:31 +0300 From: Michael Tokarev MIME-Version: 1.0 References: <1428058914-32050-1-git-send-email-bogdan.purcareata@freescale.com> <551EA099.4070702@redhat.com> In-Reply-To: <551EA099.4070702@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Bogdan Purcareata , qemu-devel@nongnu.org, qemu-stable 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. So much for trivial... ;) Thanks, /mjt