libobs/util: Don't perform calculation until data checked

master
jp9000 2015-12-21 04:52:29 -08:00
parent c6914fda45
commit c2168cf9e8
1 changed files with 2 additions and 3 deletions

View File

@ -192,12 +192,11 @@ static inline void circlebuf_push_front(struct circlebuf *cb, const void *data,
static inline void circlebuf_peek_front(struct circlebuf *cb, void *data, static inline void circlebuf_peek_front(struct circlebuf *cb, void *data,
size_t size) size_t size)
{ {
size_t start_size;
assert(size <= cb->size); assert(size <= cb->size);
start_size = cb->capacity - cb->start_pos;
if (data) { if (data) {
size_t start_size = cb->capacity - cb->start_pos;
if (start_size < size) { if (start_size < size) {
memcpy(data, (uint8_t*)cb->data + cb->start_pos, memcpy(data, (uint8_t*)cb->data + cb->start_pos,
start_size); start_size);