Eina: fix eina_file_current_directory_get()

the length was not correctly computed and eina_file_path_sanitize() was
was writing beyond the limit of the string

@fix
This commit is contained in:
Vincent Torri 2015-10-14 09:58:19 +02:00 committed by Tom Hacohen
parent cfe1817315
commit 8854b9f727
1 changed files with 7 additions and 9 deletions

View File

@ -423,21 +423,19 @@ eina_file_path_relative(const char *path)
Eina_Tmpstr * Eina_Tmpstr *
eina_file_current_directory_get(const char *path, size_t len) eina_file_current_directory_get(const char *path, size_t len)
{ {
char *cwd;
char *tmp; char *tmp;
DWORD l; DWORD l;
l = GetCurrentDirectory(0, NULL); l = GetCurrentDirectory(0, NULL);
if (l <= 0) return NULL; if (l == 0) return NULL;
cwd = alloca(sizeof(char) * (l + 1)); tmp = alloca(sizeof (char) * (l + len + 2));
GetCurrentDirectory(l + 1, cwd); l = GetCurrentDirectory(l + 1, tmp);
len += l + 2; tmp[l] = '\\';
tmp = alloca(sizeof (char) * len); memcpy(tmp + l + 1, path, len);
snprintf(tmp, len, "%s\\%s", cwd, path); tmp[l + len + 1] = '\0';
tmp[len - 1] = '\0';
return eina_tmpstr_add_length(tmp, len); return eina_tmpstr_add_length(tmp, l + len + 1);
} }
char * char *