diff options
| author | Ha Thach <[email protected]> | 2021-07-01 02:25:23 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-01 02:25:23 +0700 |
| commit | 9b3ec69b27b5d18d4c1f34d6730cec21afc8e628 (patch) | |
| tree | a6e544264d7cf411ae244f1dde07da3f5dad48a9 /src/common | |
| parent | 3b539fdd8d8e9d48756cf5f6e0d605af3972651c (diff) | |
| parent | 74b51d43e1e8e14def49c140f8f063eb56c9e4d2 (diff) | |
Merge pull request #940 from HiFiPhile/fifo_fix
Fix fifo overflow correction.
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/tusb_fifo.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 1eb886aa1..73217cf75 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -325,7 +325,7 @@ static uint16_t advance_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset) // We are exploiting the wrap around to the correct index // TODO warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] - if ((p > p + offset) || (p + offset > f->max_pointer_idx)) + if ((p > (uint16_t)(p + offset)) || ((uint16_t)(p + offset) > f->max_pointer_idx)) { p = (p + offset) + f->non_used_index_space; } @@ -342,7 +342,7 @@ static uint16_t backward_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset) // We limit the index space of p such that a correct wrap around happens // Check for a wrap around or if we are in unused index space - This has to be checked first!! // We are exploiting the wrap around to the correct index - if ((p < p - offset) || (p - offset > f->max_pointer_idx)) + if ((p < (uint16_t)(p - offset)) || ((uint16_t)(p - offset) > f->max_pointer_idx)) { p = (p - offset) - f->non_used_index_space; } |
