summaryrefslogtreecommitdiff
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)
42 42
43int lang_load(const char *filename) 43int lang_load(const char *filename)
44{ 44{
45 int filesize; 45 int fsize;
46 int fd = open(filename, O_RDONLY); 46 int fd = open(filename, O_RDONLY);
47 int retcode=0; 47 int retcode=0;
48 unsigned char lang_header[2];
48 if(fd == -1) 49 if(fd == -1)
49 return 1; 50 return 1;
50 filesize = read(fd, language_buffer, MAX_LANGUAGE_SIZE); 51 fsize = filesize(fd) - 2;
51 if(filesize != MAX_LANGUAGE_SIZE) { 52 if(fsize <= MAX_LANGUAGE_SIZE) {
52 if((language_buffer[0] == LANGUAGE_COOKIE) && 53 read(fd, lang_header, 2);
53 (language_buffer[1] == LANGUAGE_VERSION)) { 54 if((lang_header[0] == LANGUAGE_COOKIE) &&
54 unsigned char *ptr=&language_buffer[2]; 55 (lang_header[1] == LANGUAGE_VERSION)) {
56 read(fd, language_buffer, MAX_LANGUAGE_SIZE);
57 unsigned char *ptr = language_buffer;
55 int id; 58 int id;
56 lang_init(); /* initialize with builtin */ 59 lang_init(); /* initialize with builtin */
57 filesize-=2;
58 60
59 while(filesize>3) { 61 while(fsize>3) {
60 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */ 62 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
61 ptr+=2; /* pass the id */ 63 ptr+=2; /* pass the id */
62 if(id < LANG_LAST_INDEX_IN_ARRAY) { 64 if(id < LANG_LAST_INDEX_IN_ARRAY) {
@@ -67,10 +69,10 @@ int lang_load(const char *filename)
67 language_strings[id] = ptr; /* point to this string */ 69 language_strings[id] = ptr; /* point to this string */
68 } 70 }
69 while(*ptr) { /* pass the string */ 71 while(*ptr) { /* pass the string */
70 filesize--; 72 fsize--;
71 ptr++; 73 ptr++;
72 } 74 }
73 filesize-=3; /* the id and the terminating zero */ 75 fsize-=3; /* the id and the terminating zero */
74 ptr++; /* pass the terminating zero-byte */ 76 ptr++; /* pass the terminating zero-byte */
75 } 77 }
76 } 78 }
@@ -80,7 +82,7 @@ int lang_load(const char *filename)
80 } 82 }
81 } 83 }
82 else { 84 else {
83 DEBUGF("Language %s too large: %d\n", filename, filesize); 85 DEBUGF("Language %s too large: %d\n", filename, fsize);
84 retcode = 3; 86 retcode = 3;
85 } 87 }
86 close(fd); 88 close(fd);