summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2005-12-06 00:44:57 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2005-12-06 00:44:57 +0000
commit87c6f546cf8aa41b8c56019638281a154692a03b (patch)
treec0cc842d1f8bb37d1551beb0ba9845b4cfae7c1d /apps
parentb05eec8b1ea4cbad0b668a8974c87272acc78ed6 (diff)
downloadrockbox-87c6f546cf8aa41b8c56019638281a154692a03b.tar.gz
rockbox-87c6f546cf8aa41b8c56019638281a154692a03b.zip
don't load the language file into the buffer untill we know it is not too big and of the right version (files can now be 3 bytes bigger ;-)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8164 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/language.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/apps/language.c b/apps/language.c
index 7a1442517d..d374fa18ea 100644
--- a/apps/language.c
+++ b/apps/language.c
@@ -42,21 +42,23 @@ void lang_init(void)
int lang_load(const char *filename)
{
- int filesize;
+ int fsize;
int fd = open(filename, O_RDONLY);
int retcode=0;
+ unsigned char lang_header[2];
if(fd == -1)
return 1;
- filesize = read(fd, language_buffer, MAX_LANGUAGE_SIZE);
- if(filesize != MAX_LANGUAGE_SIZE) {
- if((language_buffer[0] == LANGUAGE_COOKIE) &&
- (language_buffer[1] == LANGUAGE_VERSION)) {
- unsigned char *ptr=&language_buffer[2];
+ fsize = filesize(fd) - 2;
+ if(fsize <= MAX_LANGUAGE_SIZE) {
+ read(fd, lang_header, 2);
+ if((lang_header[0] == LANGUAGE_COOKIE) &&
+ (lang_header[1] == LANGUAGE_VERSION)) {
+ read(fd, language_buffer, MAX_LANGUAGE_SIZE);
+ unsigned char *ptr = language_buffer;
int id;
lang_init(); /* initialize with builtin */
- filesize-=2;
- while(filesize>3) {
+ while(fsize>3) {
id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
ptr+=2; /* pass the id */
if(id < LANG_LAST_INDEX_IN_ARRAY) {
@@ -67,10 +69,10 @@ int lang_load(const char *filename)
language_strings[id] = ptr; /* point to this string */
}
while(*ptr) { /* pass the string */
- filesize--;
+ fsize--;
ptr++;
}
- filesize-=3; /* the id and the terminating zero */
+ fsize-=3; /* the id and the terminating zero */
ptr++; /* pass the terminating zero-byte */
}
}
@@ -80,7 +82,7 @@ int lang_load(const char *filename)
}
}
else {
- DEBUGF("Language %s too large: %d\n", filename, filesize);
+ DEBUGF("Language %s too large: %d\n", filename, fsize);
retcode = 3;
}
close(fd);