From 87e5b1193cf858e2204970b6cce36eb50fefd934 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Mon, 12 Nov 2007 15:16:41 +0000 Subject: The error checking for bitmap handling in bufopen was serioulsy broken, as loading a huge bitmap showed. Fix it and reorganise the code slightly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15597 a1c6a512-1295-4272-9138-f99709370657 --- apps/buffering.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/apps/buffering.c b/apps/buffering.c index 4176f27d22..fd386fd29f 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -884,31 +884,40 @@ int bufopen(const char *file, size_t offset, enum data_type type) } strncpy(h->path, file, MAX_PATH); - h->filerem = size - offset; h->offset = offset; h->ridx = buf_widx; - h->widx = buf_widx; h->data = buf_widx; - h->available = 0; h->type = type; #ifdef HAVE_ALBUMART - if (type == TYPE_BITMAP) { + if (type == TYPE_BITMAP) + { /* Bitmap file: we load the data instead of the file */ + int rc; mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ - size = load_bitmap(fd); - if (size <= 0) + rc = load_bitmap(fd); + if (rc <= 0) + { + rm_handle(h); + close(fd); + mutex_unlock(&llist_mutex); return ERR_FILE_ERROR; - + } h->filerem = 0; - h->available = size; - h->widx = buf_widx + size; /* safe because the data doesn't wrap */ - buf_widx += size; /* safe too */ + h->filesize = rc; + h->available = rc; + h->widx = buf_widx + rc; /* safe because the data doesn't wrap */ + buf_widx += rc; /* safe too */ mutex_unlock(&llist_mutex); } + else #endif - - h->filesize = size; + { + h->filerem = size - offset; + h->filesize = size; + h->available = 0; + h->widx = buf_widx; + } if (type == TYPE_CUESHEET) { h->fd = fd; -- cgit v1.2.3