From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnxE8-0005Mv-GF for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:33:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SnxE6-0005el-Sg for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:33:04 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:42562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnxE6-0005eY-Lo for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:33:02 -0400 Received: by bkcji1 with SMTP id ji1so1816605bkc.4 for ; Sun, 08 Jul 2012 12:33:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: Date: Sun, 8 Jul 2012 20:32:59 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH] bitops: fix types List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org On 8 July 2012 20:12, Blue Swirl wrote: > On Sun, Jul 8, 2012 at 6:54 PM, Peter Maydell wrote: >> On 8 July 2012 19:32, Blue Swirl wrote: >>> On Sun, Jul 8, 2012 at 2:04 PM, Peter Maydell wrote: >>>> On 8 July 2012 13:12, wrote: >>>>> -static inline uint64_t deposit64(uint64_t value, int start, int length, >>>>> - uint64_t fieldval) >>>>> +static inline uint64_t deposit64(uint64_t value, unsigned int start, >>>>> + unsigned int length, uint64_t fieldval) >>>>> { >>>>> uint64_t mask; >>>>> - assert(start >= 0 && length > 0 && length <= 64 - start); >>>>> + assert(length > 0 && length <= 64 - start); >>>> >>>> This breaks the assertion (consider the case of start == UINT_MAX >>>> and length == 64). >>> >>> The original is equally buggy in other cases since there is no bound >>> check for the upper limit. >> >> For what upper limit? Overlong length or start should both be caught >> by the third condition in the signed case. > > Nice. Why is it written like that, I'd use > start + length <= 64? That would fail to handle the case of start == length == INT_MAX. -- PMM