[vlc-devel] [PATCH] atomic: prevent overflow

Romain Vimont rom1v at videolabs.io
Mon Feb 24 10:00:55 CET 2020


OK then.

On 2/24/20 9:57 AM, Rémi Denis-Courmont wrote:
> Hi,
> 
> There is some rationale for uintptr: if you have at least one pointer 
> per ref, you can't have more than UINTPTR_MAX (divided by sizeof (void 
> *)) refs.
> 
> With uintmax, I don't see it. Also uintmax might not be supported as 
> atomic if it's 128-bits.
> 
> Le 24 février 2020 10:52:40 GMT+02:00, Romain Vimont 
> <rom1v at videolabs.io> a écrit :
> 
>     LGTM
> 
>     But maybe uintmax_t is more appropriate than uintptr_t (semantically).
> 
>     On 2/24/20 9:33 AM, quentin.chateau at deepskycorp.com wrote:
> 
>         From: Quentin Chateau <quentin.chateau at deepskycorp.com>
>         ------------------------------------------------------------------------
>         include/vlc_atomic.h | 6 +++---
>         1 file changed, 3 insertions(+), 3 deletions(-)
> 
>         diff --git a/include/vlc_atomic.h b/include/vlc_atomic.h
>         index e2d4fe5360..625738849a 100644
>         --- a/include/vlc_atomic.h
>         +++ b/include/vlc_atomic.h
>         @@ -60,7 +60,7 @@ static inline void
>         vlc_atomic_store_float(vlc_atomic_float *atom, float f)
>         }
> 
>         typedef struct vlc_atomic_rc_t {
>         - atomic_uint refs;
>         + atomic_uintptr_t refs;
>         } vlc_atomic_rc_t;
> 
>         /** Init the RC to 1 */
>         @@ -72,7 +72,7 @@ static inline void
>         vlc_atomic_rc_init(vlc_atomic_rc_t *rc)
>         /** Increment the RC */
>         static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
>         {
>         - unsigned prev = atomic_fetch_add_explicit(&rc->refs, 1,
>         memory_order_relaxed);
>         + uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, 1,
>         memory_order_relaxed);
>         vlc_assert(prev);
>         VLC_UNUSED(prev);
>         }
>         @@ -80,7 +80,7 @@ static inline void
>         vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
>         /** Decrement the RC and return true if it reaches 0 */
>         static inline bool vlc_atomic_rc_dec(vlc_atomic_rc_t *rc)
>         {
>         - unsigned prev = atomic_fetch_sub_explicit(&rc->refs, 1,
>         memory_order_acq_rel);
>         + uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, 1,
>         memory_order_acq_rel);
>         vlc_assert(prev);
>         return prev == 1;
>         }
> 
>     ------------------------------------------------------------------------
>     vlc-devel mailing list
>     To unsubscribe or modify your subscription options:
>     https://mailman.videolan.org/listinfo/vlc-devel
> 
> 
> -- 
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser 
> ma brièveté.
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list