summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-05-27 11:21:08 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-05-27 11:21:08 +0000
commit196b770a96920e93dff514b9173d290bf73d0a81 (patch)
treef8a972d7892fb2f152dc8d58a37f6dc7d41c7109
parent45975987b2a18b607c35e05aa7090f102246fdcc (diff)
downloadrockbox-196b770a96920e93dff514b9173d290bf73d0a81.tar.gz
rockbox-196b770a96920e93dff514b9173d290bf73d0a81.zip
Init dircache after applying settings and use a splash. Possible prevent
some type of buffer overflow with tagcache. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9997 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/main.c37
-rw-r--r--apps/tagcache.c4
2 files changed, 18 insertions, 23 deletions
diff --git a/apps/main.c b/apps/main.c
index 84c77ab1c9..3878e3a9c4 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -106,33 +106,25 @@ void init_dircache(void)
106 int font_w, font_h; 106 int font_w, font_h;
107 int result; 107 int result;
108 char buf[32]; 108 char buf[32];
109 bool clear = false;
109 110
110 dircache_init(); 111 dircache_init();
111 if (global_settings.dircache) 112 if (global_settings.dircache)
112 { 113 {
113 /* Print "Scanning disk..." to the display. */ 114 if (global_settings.dircache_size == 0)
114 lcd_getstringsize("A", &font_w, &font_h);
115 lcd_putsxy((LCD_WIDTH/2) - ((strlen(str(LANG_DIRCACHE_BUILDING))*font_w)/2),
116 LCD_HEIGHT-font_h*3, str(LANG_DIRCACHE_BUILDING));
117 lcd_update();
118
119 result = dircache_build(global_settings.dircache_size);
120 if (result < 0)
121 { 115 {
122 snprintf(buf, sizeof(buf), 116 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
123 "Failed! Result: %d", 117 clear = true;
124 result);
125 lcd_getstringsize("A", &font_w, &font_h);
126 lcd_putsxy((LCD_WIDTH/2) - ((strlen(buf)*font_w)/2),
127 LCD_HEIGHT-font_h*2, buf);
128 } 118 }
129 else 119
120 result = dircache_build(global_settings.dircache_size);
121 if (result < 0)
122 gui_syncsplash(0, true, "Failed! Result: %d", result);
123
124 if (clear)
130 { 125 {
131 /* Clean the text when we are done. */ 126 backlight_on();
132 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 127 show_logo();
133 lcd_fillrect(0, LCD_HEIGHT-font_h*3, LCD_WIDTH, font_h);
134 lcd_set_drawmode(DRMODE_SOLID);
135 lcd_update();
136 } 128 }
137 } 129 }
138} 130}
@@ -170,7 +162,10 @@ void init_tagcache(void)
170 tagtree_init(); 162 tagtree_init();
171 163
172 if (clear) 164 if (clear)
165 {
166 backlight_on();
173 show_logo(); 167 show_logo();
168 }
174} 169}
175 170
176#ifdef SIMULATOR 171#ifdef SIMULATOR
@@ -389,9 +384,9 @@ void init(void)
389 settings_load(SETTINGS_ALL); 384 settings_load(SETTINGS_ALL);
390 385
391 386
392 init_dircache();
393 gui_sync_wps_init(); 387 gui_sync_wps_init();
394 settings_apply(); 388 settings_apply();
389 init_dircache();
395 init_tagcache(); 390 init_tagcache();
396 391
397 status_init(); 392 status_init();
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 127c6aa63a..f4e139aafa 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -1427,7 +1427,6 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
1427 1427
1428 tempbufidx = 0; 1428 tempbufidx = 0;
1429 tempbuf_pos = TAGFILE_MAX_ENTRIES * sizeof(struct tempbuf_searchidx); 1429 tempbuf_pos = TAGFILE_MAX_ENTRIES * sizeof(struct tempbuf_searchidx);
1430 memset(tempbuf+tempbuf_pos, 0, LOOKUP_BUF_DEPTH * sizeof(void **));
1431 tempbuf_pos += LOOKUP_BUF_DEPTH * sizeof(void **); 1430 tempbuf_pos += LOOKUP_BUF_DEPTH * sizeof(void **);
1432 tempbuf_left = tempbuf_size - tempbuf_pos - 8; 1431 tempbuf_left = tempbuf_size - tempbuf_pos - 8;
1433 if (tempbuf_left - TAGFILE_ENTRY_AVG_LENGTH * TAGFILE_MAX_ENTRIES < 0) 1432 if (tempbuf_left - TAGFILE_ENTRY_AVG_LENGTH * TAGFILE_MAX_ENTRIES < 0)
@@ -1438,6 +1437,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
1438 1437
1439 lookup = (struct tempbuf_searchidx **) 1438 lookup = (struct tempbuf_searchidx **)
1440 (tempbuf + sizeof(struct tempbuf_searchidx)*TAGFILE_MAX_ENTRIES); 1439 (tempbuf + sizeof(struct tempbuf_searchidx)*TAGFILE_MAX_ENTRIES);
1440 memset(lookup, 0, LOOKUP_BUF_DEPTH * sizeof(void **));
1441 1441
1442 /* Open the index file, which contains the tag names. */ 1442 /* Open the index file, which contains the tag names. */
1443 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); 1443 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type);
@@ -2024,7 +2024,7 @@ static bool allocate_tagcache(void)
2024 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); 2024 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *);
2025 logf("tagcache: %d bytes allocated.", stat.ramcache_allocated); 2025 logf("tagcache: %d bytes allocated.", stat.ramcache_allocated);
2026 logf("at: 0x%04x", audiobuf); 2026 logf("at: 0x%04x", audiobuf);
2027 audiobuf += (long)((stat.ramcache_allocated & ~0x03) + 0x04); 2027 audiobuf += (long)((stat.ramcache_allocated & ~0x03) + 128);
2028 2028
2029 return true; 2029 return true;
2030} 2030}