2024-02-07 15:32:42

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v5 3/3] overflow: Introduce wrapping_inc() and wrapping_dec()

On Wed, Feb 7, 2024 at 5:24 PM Kees Cook <[email protected]> wrote:
>
> This allows replacements of the idioms "var += offset" and "var -= offset"
> with the wrapping_inc() and wrapping_dec() helpers respectively. They
> will avoid wrap-around sanitizer instrumentation.
>
> Add to the selftests to validate behavior and lack of side-effects.

I would expect inc/dec to add/subtract 1. So, to me the terminology is
confusing. The list of the C/C++ operators on Wikipedia describes
above as

+= Assignment by sum
-= Assignment by difference


Hence the proposal is to have

wrapping_sum()
wrapping_diff()

--
With Best Regards,
Andy Shevchenko


2024-02-07 16:08:26

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH v5 3/3] overflow: Introduce wrapping_inc() and wrapping_dec()

On Wed, Feb 07, 2024 at 05:31:54PM +0200, Andy Shevchenko wrote:
> On Wed, Feb 7, 2024 at 5:24 PM Kees Cook <[email protected]> wrote:
> >
> > This allows replacements of the idioms "var += offset" and "var -= offset"
> > with the wrapping_inc() and wrapping_dec() helpers respectively. They
> > will avoid wrap-around sanitizer instrumentation.
> >
> > Add to the selftests to validate behavior and lack of side-effects.
>
> I would expect inc/dec to add/subtract 1. So, to me the terminology is
> confusing. The list of the C/C++ operators on Wikipedia describes
> above as
>
> += Assignment by sum
> -= Assignment by difference
>
>
> Hence the proposal is to have
>
> wrapping_sum()
> wrapping_diff()

I think maybe the missing phrase is "assign", which is what makes
argument 1 "special" -- it's being changed. Perhaps:

wrapping_add_assign()
wrapping_sub_assign()

?

--
Kees Cook