[vlc-devel] [PATCH 1/2] Add helpers for unsigned integer overflow

Rémi Denis-Courmont remi at remlab.net
Sun Nov 12 14:31:11 CET 2017


On dimanche 12 novembre 2017 13:44:21 EET Romain Vimont wrote:
> Le dimanche 12 novembre 2017 à 11:27 +0200, Rémi Denis-Courmont a écrit :
> > ---
> > 
> >  include/vlc_common.h | 114
> >  +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114
> >  insertions(+)
> > 
> > diff --git a/include/vlc_common.h b/include/vlc_common.h
> > index ed5ff77730..e3d7086ff7 100644
> > --- a/include/vlc_common.h
> > +++ b/include/vlc_common.h
> > @@ -661,6 +661,120 @@ static inline uint64_t (bswap64)(uint64_t x)
> > 
> >  #endif
> >  }
> > 
> > +/* Integer overflow */
> > +static inline bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
> > +{
> > +#ifdef __GNUC__
> > +     return __builtin_uadd_overflow(a, b, res);
> > +#else
> > +     *res = a + b;
> > +     return (a + b) > a;
> 
> (a + b) < a

Yes. My evil scheme to break clang builds has been foiled.

-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list