From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJNNX-0001pa-Bb for qemu-devel@nongnu.org; Tue, 10 Sep 2013 08:49:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJNNR-0000ej-CA for qemu-devel@nongnu.org; Tue, 10 Sep 2013 08:49:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJNNR-0000ee-4O for qemu-devel@nongnu.org; Tue, 10 Sep 2013 08:49:05 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8ACn4uR019679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 10 Sep 2013 08:49:04 -0400 Date: Tue, 10 Sep 2013 15:51:10 +0300 From: "Michael S. Tsirkin" Message-ID: <20130910125110.GA2121@redhat.com> References: <1378291667-8516-1-git-send-email-mst@redhat.com> <1378291667-8516-4-git-send-email-mst@redhat.com> <20130910113554.7d988986@nial.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130910113554.7d988986@nial.usersys.redhat.com> Subject: Re: [Qemu-devel] [PATCH 3/6] range: add min/max operations on ranges List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: qemu-devel@nongnu.org On Tue, Sep 10, 2013 at 11:35:54AM +0200, Igor Mammedov wrote: > On Wed, 4 Sep 2013 13:48:35 +0300 > "Michael S. Tsirkin" wrote: > > > Signed-off-by: Michael S. Tsirkin > > --- > > include/qemu/range.h | 17 +++++++++++++++++ > > 1 file changed, 17 insertions(+) > > > > diff --git a/include/qemu/range.h b/include/qemu/range.h > > index 4a0780d..1c688ca 100644 > > --- a/include/qemu/range.h > > +++ b/include/qemu/range.h > > @@ -17,6 +17,23 @@ struct Range { > > uint64_t end; /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ > > }; > > > > +static inline void range_extend(Range *range, Range *extend_by) > doc comment what it does pls. > > > +{ > > + if (!extend_by->begin && !extend_by->end) { > > + return; > > + } > > + if (!range->begin && !range->end) { > > + *range = *extend_by; > > + return; > > + } > > + if (range->begin > extend_by->begin) { > > + range->begin = extend_by->begin; > > + } > > + if (range->end - 1 < extend_by->end - 1) { > (foo)->end could be 0 at this point leading to overflow when subtracted, > is it intended to be so? Absolutely - as the comment near this field definition states: 0 means region ends at ~0x0LL. > > + range->end = extend_by->end; > > + } > > +} > > + > > /* Get last byte of a range from offset + length. > > * Undefined for ranges that wrap around 0. */ > > static inline uint64_t range_get_last(uint64_t offset, uint64_t len) >