summaryrefslogtreecommitdiff
path: root/lib/rbcodec
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec')
-rw-r--r--lib/rbcodec/metadata/asap.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/rbcodec/metadata/asap.c b/lib/rbcodec/metadata/asap.c
index b1cd649d89..47eb2a3d50 100644
--- a/lib/rbcodec/metadata/asap.c
+++ b/lib/rbcodec/metadata/asap.c
@@ -33,6 +33,14 @@
33#include "platform.h" 33#include "platform.h"
34#define MAX_SONGS 32 34#define MAX_SONGS 32
35 35
36static char readchar(int fd, char failchr)
37{
38 char ch;
39 if (read(fd,&ch,sizeof(ch)) == sizeof(ch))
40 return ch;
41 return failchr;
42}
43
36static bool parse_dec(int *retval, const char *p, int minval, int maxval) 44static bool parse_dec(int *retval, const char *p, int minval, int maxval)
37{ 45{
38 int r = 0; 46 int r = 0;
@@ -73,10 +81,13 @@ static bool parse_text(char *retval, const char *p)
73 81
74static int ASAP_ParseDuration(const char *s) 82static int ASAP_ParseDuration(const char *s)
75{ 83{
76 int r; 84 #define chk_digit(rtn) if (*s < '0' || *s > '9') {return (rtn);}
77 if (*s < '0' || *s > '9') 85 #define set_digit(mult) r += (mult) * (*s++ - '0')
78 return -1; 86 #define parse_digit(m) chk_digit(r) set_digit(m)
79 r = *s++ - '0'; 87
88 int r = 0;
89 chk_digit(-1);
90 set_digit(1);
80 if (*s >= '0' && *s <= '9') 91 if (*s >= '0' && *s <= '9')
81 r = 10 * r + *s++ - '0'; 92 r = 10 * r + *s++ - '0';
82 if (*s == ':') { 93 if (*s == ':') {
@@ -84,23 +95,18 @@ static int ASAP_ParseDuration(const char *s)
84 if (*s < '0' || *s > '5') 95 if (*s < '0' || *s > '5')
85 return -1; 96 return -1;
86 r = 60 * r + (*s++ - '0') * 10; 97 r = 60 * r + (*s++ - '0') * 10;
87 if (*s < '0' || *s > '9') 98 chk_digit(-1);
88 return -1; 99 set_digit(1);
89 r += *s++ - '0';
90 } 100 }
101
91 r *= 1000; 102 r *= 1000;
92 if (*s != '.') 103 if (*s != '.')
93 return r; 104 return r;
94 s++; 105 s++;
95 if (*s < '0' || *s > '9') 106 parse_digit(100);
96 return r; 107 parse_digit(10);
97 r += 100 * (*s++ - '0'); 108 parse_digit(1);
98 if (*s < '0' || *s > '9') 109
99 return r;
100 r += 10 * (*s++ - '0');
101 if (*s < '0' || *s > '9')
102 return r;
103 r += *s - '0';
104 return r; 110 return r;
105} 111}
106 112
@@ -126,6 +132,7 @@ static bool read_asap_string(char* source, char** buf, char** buffer_end, char**
126 132
127static bool parse_sap_header(int fd, struct mp3entry* id3, int file_len) 133static bool parse_sap_header(int fd, struct mp3entry* id3, int file_len)
128{ 134{
135 #define EOH_CHAR (0xFF)
129 int module_index = 0; 136 int module_index = 0;
130 int sap_signature = -1; 137 int sap_signature = -1;
131 int duration_index = 0; 138 int duration_index = 0;
@@ -151,10 +158,9 @@ static bool parse_sap_header(int fd, struct mp3entry* id3, int file_len)
151 158
152 if (module_index + 8 >= file_len) 159 if (module_index + 8 >= file_len)
153 return false; 160 return false;
154 /* read a char */ 161 cur_char = readchar(fd, EOH_CHAR);
155 read(fd,&cur_char,1);
156 /* end of header */ 162 /* end of header */
157 if (cur_char == 0xff) 163 if (cur_char == EOH_CHAR)
158 break; 164 break;
159 165
160 i = 0; 166 i = 0;
@@ -164,13 +170,11 @@ static bool parse_sap_header(int fd, struct mp3entry* id3, int file_len)
164 module_index++; 170 module_index++;
165 if (module_index >= file_len || (unsigned)i >= sizeof(line) - 1) 171 if (module_index >= file_len || (unsigned)i >= sizeof(line) - 1)
166 return false; 172 return false;
167 /* read a char */ 173 cur_char = readchar(fd, 0x0d);
168 read(fd,&cur_char,1);
169 } 174 }
170 if (++module_index >= file_len ) 175 if (++module_index >= file_len )
171 return false; 176 return false;
172 /* read a char */ 177 cur_char = readchar(fd, EOH_CHAR);
173 read(fd,&cur_char,1);
174 if ( cur_char != 0x0a) 178 if ( cur_char != 0x0a)
175 return false; 179 return false;
176 180