summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-12 15:16:41 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-12 15:16:41 +0000
commit87e5b1193cf858e2204970b6cce36eb50fefd934 (patch)
treed23bab8400118beabfe840b8e57e431fdf001b34 /apps/buffering.c
parent1480d078e7d6c55e91a60050f1f943468c6fe89c (diff)
downloadrockbox-87e5b1193cf858e2204970b6cce36eb50fefd934.tar.gz
rockbox-87e5b1193cf858e2204970b6cce36eb50fefd934.zip
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
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c33
1 files 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)
884 } 884 }
885 885
886 strncpy(h->path, file, MAX_PATH); 886 strncpy(h->path, file, MAX_PATH);
887 h->filerem = size - offset;
888 h->offset = offset; 887 h->offset = offset;
889 h->ridx = buf_widx; 888 h->ridx = buf_widx;
890 h->widx = buf_widx;
891 h->data = buf_widx; 889 h->data = buf_widx;
892 h->available = 0;
893 h->type = type; 890 h->type = type;
894 891
895#ifdef HAVE_ALBUMART 892#ifdef HAVE_ALBUMART
896 if (type == TYPE_BITMAP) { 893 if (type == TYPE_BITMAP)
894 {
897 /* Bitmap file: we load the data instead of the file */ 895 /* Bitmap file: we load the data instead of the file */
896 int rc;
898 mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ 897 mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */
899 size = load_bitmap(fd); 898 rc = load_bitmap(fd);
900 if (size <= 0) 899 if (rc <= 0)
900 {
901 rm_handle(h);
902 close(fd);
903 mutex_unlock(&llist_mutex);
901 return ERR_FILE_ERROR; 904 return ERR_FILE_ERROR;
902 905 }
903 h->filerem = 0; 906 h->filerem = 0;
904 h->available = size; 907 h->filesize = rc;
905 h->widx = buf_widx + size; /* safe because the data doesn't wrap */ 908 h->available = rc;
906 buf_widx += size; /* safe too */ 909 h->widx = buf_widx + rc; /* safe because the data doesn't wrap */
910 buf_widx += rc; /* safe too */
907 mutex_unlock(&llist_mutex); 911 mutex_unlock(&llist_mutex);
908 } 912 }
913 else
909#endif 914#endif
910 915 {
911 h->filesize = size; 916 h->filerem = size - offset;
917 h->filesize = size;
918 h->available = 0;
919 h->widx = buf_widx;
920 }
912 921
913 if (type == TYPE_CUESHEET) { 922 if (type == TYPE_CUESHEET) {
914 h->fd = fd; 923 h->fd = fd;