Le 07/03/2018 à 18:45, Max Filippov a écrit :
> On Wed, Mar 7, 2018 at 2:08 AM, Laurent Vivier <laur...@vivier.eu> wrote:
>>> +static inline int guest_range_valid(unsigned long start, unsigned long len)
>>> +{
>>> +    if (len)
>>> +        return guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len 
>>> + 1;
>>> +    else
>>> +        return guest_addr_valid(start);
>>> +}
>>
>> I think we can consider len == 0 is invalid and use only:
>>
>>   return start + (len - 1) <= GUEST_ADDR_MAX;
> 
> start + len - 1 may wrap around, that's why I first validate len and then have
> len at the right side of the comparison. I.e. if we drop check for len == 0 
> I'd
> still write it as
> 
>   guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len + 1;
> 

Yes, you're right.

it would be clearer to write:

    len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;

but it's only cosmetic.

Thanks,
Laurent

Reply via email to