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

quentin.chateau at deepskycorp.com quentin.chateau at deepskycorp.com
Mon Feb 24 09:33:35 CET 2020


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;
 }
-- 
2.17.1



More information about the vlc-devel mailing list