utils/fifo8: change fatal errors from abort() to assert()
Developer errors are better represented with assert() rather than abort(). Also improve the strictness of the checks by using range checks within the assert() rather than converting the existing equality checks to inequality checks. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Reviewed-by: Claudio Fontana <cfontana@suse.de> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20210121102518.20112-1-mark.cave-ayland@ilande.co.uk>
This commit is contained in:
parent
5b19cb63d9
commit
f71407ed2f
16
util/fifo8.c
16
util/fifo8.c
@ -31,9 +31,7 @@ void fifo8_destroy(Fifo8 *fifo)
|
|||||||
|
|
||||||
void fifo8_push(Fifo8 *fifo, uint8_t data)
|
void fifo8_push(Fifo8 *fifo, uint8_t data)
|
||||||
{
|
{
|
||||||
if (fifo->num == fifo->capacity) {
|
assert(fifo->num < fifo->capacity);
|
||||||
abort();
|
|
||||||
}
|
|
||||||
fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
|
fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
|
||||||
fifo->num++;
|
fifo->num++;
|
||||||
}
|
}
|
||||||
@ -42,9 +40,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
|
|||||||
{
|
{
|
||||||
uint32_t start, avail;
|
uint32_t start, avail;
|
||||||
|
|
||||||
if (fifo->num + num > fifo->capacity) {
|
assert(fifo->num + num <= fifo->capacity);
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
start = (fifo->head + fifo->num) % fifo->capacity;
|
start = (fifo->head + fifo->num) % fifo->capacity;
|
||||||
|
|
||||||
@ -63,9 +59,7 @@ uint8_t fifo8_pop(Fifo8 *fifo)
|
|||||||
{
|
{
|
||||||
uint8_t ret;
|
uint8_t ret;
|
||||||
|
|
||||||
if (fifo->num == 0) {
|
assert(fifo->num > 0);
|
||||||
abort();
|
|
||||||
}
|
|
||||||
ret = fifo->data[fifo->head++];
|
ret = fifo->data[fifo->head++];
|
||||||
fifo->head %= fifo->capacity;
|
fifo->head %= fifo->capacity;
|
||||||
fifo->num--;
|
fifo->num--;
|
||||||
@ -76,9 +70,7 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num)
|
|||||||
{
|
{
|
||||||
uint8_t *ret;
|
uint8_t *ret;
|
||||||
|
|
||||||
if (max == 0 || max > fifo->num) {
|
assert(max > 0 && max <= fifo->num);
|
||||||
abort();
|
|
||||||
}
|
|
||||||
*num = MIN(fifo->capacity - fifo->head, max);
|
*num = MIN(fifo->capacity - fifo->head, max);
|
||||||
ret = &fifo->data[fifo->head];
|
ret = &fifo->data[fifo->head];
|
||||||
fifo->head += *num;
|
fifo->head += *num;
|
||||||
|
Loading…
Reference in New Issue
Block a user