[haiku-commits] Re: haiku: hrev53988 - src/system/kernel/vm

  • From: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 16 Mar 2020 17:50:49 +0100

On Mon, Mar 16, 2020 at 12:28:41PM -0400, waddlesplash wrote:

+     if (IS_USER_ADDRESS(address))
+             return IS_USER_ADDRESS(address + size);
+     else
+             return !IS_USER_ADDRESS(address + size);

Superfluous and misleading else.


How so?

If the address is not a user one, the end address needs to also not be a
user one. What else do you propose for logic here?
 
According to the coding style it should be written as (functionally
equivalent):

if (IS_USER_ADDRESS(address))
    return IS_USER_ADDRESS(address + size);
return !IS_USER_ADDRESS(address + size);

However I think the way you wrote it is clearer in this case.

I thought about that case when writing this, yes, and I remember thinking
of a case where that check was insufficient, but now I can't think of it.

I guess the validation only needs to occur on the destination side; the
source side needs a "soft" boundary check. I'll make the changes later
today.

The source needs to be validated up to min(passed size, strlen).
Basically this means implementing the function, as there is no other way
than iterate it to find the NULL terminator, and you may as well do the
copy while you do that...

-- 
Adrien.

Other related posts: