Dynamic buffers for filenames

This commit is contained in:
simon.kagstrom 2010-01-30 08:17:42 +00:00
parent fecfac664f
commit 00ee6da738
2 changed files with 10 additions and 6 deletions

View File

@ -69,10 +69,11 @@ public:
"%s/%s", this->cur_path_prefix, fileName); "%s/%s", this->cur_path_prefix, fileName);
if (ext_matches_list(fileName, prg_exts)) { if (ext_matches_list(fileName, prg_exts)) {
char tmp_filename[255]; char *tmp_filename;
FILE *src, *dst; FILE *src, *dst;
snprintf(tmp_filename, sizeof(tmp_filename), "%s/a", Gui::gui->tmp_path); tmp_filename = (char *)xmalloc(strlen(Gui::gui->tmp_path) + 4);
sprintf(tmp_filename, "%s/a", Gui::gui->tmp_path);
/* Clean temp dir first (we only want one file) */ /* Clean temp dir first (we only want one file) */
unlink(tmp_filename); unlink(tmp_filename);
@ -99,6 +100,7 @@ public:
} }
fclose(src); fclose(src);
} }
free(tmp_filename);
} }
Gui::gui->timerController->disarm(this); Gui::gui->timerController->disarm(this);

View File

@ -58,7 +58,7 @@ public:
virtual void selectCallback(int which) virtual void selectCallback(int which)
{ {
const char *fileName = this->pp_msgs[this->cur_sel]; const char *fileName = this->pp_msgs[this->cur_sel];
char buf[255]; char *new_path;
/* If we selected a directory, just take the next one */ /* If we selected a directory, just take the next one */
if (fileName[0] == '[') if (fileName[0] == '[')
@ -66,13 +66,15 @@ public:
this->pushDirectory(fileName); this->pushDirectory(fileName);
return; return;
} }
new_path = (char *)xmalloc(strlen(this->cur_path_prefix) + 3 + strlen(fileName));
snprintf(buf, sizeof(buf), "%s/%s", sprintf(new_path, "%s/%s",
this->cur_path_prefix, fileName); this->cur_path_prefix, fileName);
if (this->loadSnapshot) if (this->loadSnapshot)
TheC64->LoadSnapshot(buf); TheC64->LoadSnapshot(new_path);
else else
unlink(buf); unlink(new_path);
free(new_path);
Gui::gui->popView(); Gui::gui->popView();
} }