From 7cac18f94b512d8541456c2a68f7bfb05a5bd6e8 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 13 Mar 2011 11:56:51 +0000 Subject: [PATCH] Use ringbuf_add in buffering when incrementing for initial allocation of non-wrapping data. The result of the shortcut would have been wrong if the handle used space exactly to the end of the buffer since buf_widx wouldn't have been properly wrapped to index 0. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29578 a1c6a512-1295-4272-9138-f99709370657 --- apps/buffering.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/buffering.c b/apps/buffering.c index 2949a81a87..0cd81df93a 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -950,8 +950,8 @@ int bufopen(const char *file, size_t offset, enum data_type type, h->type = type; strlcpy(h->path, file, MAX_PATH); - buf_widx += sizeof(struct mp3entry); /* safe because the handle - can't wrap */ + buf_widx = ringbuf_add(buf_widx, sizeof(struct mp3entry)); + h->filerem = sizeof(struct mp3entry); /* Inform the buffering thread that we added a handle */ @@ -1037,8 +1037,8 @@ int bufopen(const char *file, size_t offset, enum data_type type, } else { h->filesize = rc; h->available = rc; - h->widx = buf_widx + rc; /* safe because the data doesn't wrap */ - buf_widx += rc; /* safe too */ + buf_widx = ringbuf_add(buf_widx, rc); + h->widx = buf_widx; } } else @@ -1107,12 +1107,11 @@ int bufalloc(const void *src, size_t size, enum data_type type) h->filesize = size; h->offset = 0; h->ridx = buf_widx; - h->widx = buf_widx + size; /* safe because the data doesn't wrap */ h->data = buf_widx; + buf_widx = ringbuf_add(buf_widx, size); + h->widx = buf_widx; h->available = size; h->type = type; - - buf_widx += size; /* safe too */ } mutex_unlock(&llist_mutex);