Fix wrong sprintf usage: the parameters use the restrict keyword so they may not point to the same location.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5286 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-04-06 15:02:09 +00:00
parent 33a005c801
commit c26a34d4a5
1 changed files with 35 additions and 30 deletions

View File

@ -492,32 +492,37 @@ bool DeleteDirRecursively(const char *directory)
//Create directory and copy contents (does not overwrite existing files) //Create directory and copy contents (does not overwrite existing files)
void CopyDir(const char *source_path, const char *dest_path) void CopyDir(const char *source_path, const char *dest_path)
{ {
if (!File::Exists(source_path)) if (!strcmp(source_path, dest_path)) return;
return; if (!File::Exists(source_path)) return;
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path); if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
char *virtualName; char *virtualName;
struct dirent dirent, *result = NULL; struct dirent dirent, *result = NULL;
DIR *dirp = opendir(source_path); DIR *dirp = opendir(source_path);
if (!dirp) if (!dirp) return;
return;
while (!readdir_r(dirp, &dirent, &result) && result) { while (!readdir_r(dirp, &dirent, &result) && result)
{
virtualName = result->d_name; virtualName = result->d_name;
// check for "." and ".." // check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) || if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') && ((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0'))) (virtualName[2] == '\0')))
continue; continue;
char source[300], dest[300];
char source[FILENAME_MAX], dest[FILENAME_MAX];
sprintf(source, "%s%s", source_path, virtualName); sprintf(source, "%s%s", source_path, virtualName);
sprintf(dest, "%s%s", dest_path, virtualName); sprintf(dest, "%s%s", dest_path, virtualName);
if (IsDirectory(source)) { if (IsDirectory(source))
sprintf(source, "%s/", source); {
sprintf(dest, "%s/", dest); const unsigned int srclen = strlen(source);
const unsigned int destlen = strlen(dest);
source[srclen] = '/'; source[srclen+1] = '\0';
dest[destlen] = '/'; dest[destlen+1] = '\0';
if (!File::Exists(dest)) File::CreateFullPath(dest); if (!File::Exists(dest)) File::CreateFullPath(dest);
CopyDir(source, dest); CopyDir(source, dest);
} else }
if (!File::Exists(dest)) File::Copy(source, dest); else if (!File::Exists(dest)) File::Copy(source, dest);
} }
closedir(dirp); closedir(dirp);
} }