From 95f8a3aaceb0978cd12e9fc88095503ee3e44cda Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 14 Jun 2021 00:43:08 +0200 Subject: [PATCH] Explicitly prevent unsigned int wrap-around This is a NOOP (0 - 1) + 2 == (0 + 2) - 1 but avoids a unsigned int wrap-wrap around for good measure. --- libs/pbd/pbd/playback_buffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/pbd/pbd/playback_buffer.h b/libs/pbd/pbd/playback_buffer.h index ab2cfe8ca7..4586bab45a 100644 --- a/libs/pbd/pbd/playback_buffer.h +++ b/libs/pbd/pbd/playback_buffer.h @@ -90,7 +90,7 @@ public: guint rv; if (w > r) { - rv = (r - w + size) & size_mask; + rv = ((r + size) - w) & size_mask; } else if (w < r) { rv = (r - w); } else { @@ -119,7 +119,7 @@ public: if (w > r) { return w - r; } else { - return (w - r + size) & size_mask; + return ((w + size) - r) & size_mask; } }