Protect ring-buffer write from nullptr

master
Xavier Arteaga 4 years ago committed by Xavier Arteaga
parent 369cffec00
commit c2621cc4f8

@ -147,6 +147,7 @@ int srslte_ringbuffer_write_timed_block(srslte_ringbuffer_t* q, void* p, int nof
} else if (!q->active) {
ret = SRSLTE_SUCCESS;
} else if (ret == SRSLTE_SUCCESS) {
if (ptr != NULL) {
if (w_bytes > q->capacity - q->wpm) {
int x = q->capacity - q->wpm;
memcpy(&q->buffer[q->wpm], ptr, x);
@ -154,6 +155,15 @@ int srslte_ringbuffer_write_timed_block(srslte_ringbuffer_t* q, void* p, int nof
} else {
memcpy(&q->buffer[q->wpm], ptr, w_bytes);
}
} else {
if (w_bytes > q->capacity - q->wpm) {
int x = q->capacity - q->wpm;
memset(&q->buffer[q->wpm], 0, x);
memset(q->buffer, 0, w_bytes - x);
} else {
memset(&q->buffer[q->wpm], 0, w_bytes);
}
}
q->wpm += w_bytes;
if (q->wpm >= q->capacity) {
q->wpm -= q->capacity;

Loading…
Cancel
Save