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" <m...@redhat.com> wrote: > > > Signed-off-by: Michael S. Tsirkin <m...@redhat.com> > > --- > > 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) >