mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
(vfs_mkstemps): don't allocate a large memory chunk.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
97fe1a706d
commit
b7c54f64bb
@ -177,13 +177,13 @@ int
|
|||||||
vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_basename)
|
vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_basename)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
char *suffix, *q;
|
GString *suffix;
|
||||||
int shift;
|
int shift;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Strip directories */
|
/* Strip directories */
|
||||||
p = strrchr (param_basename, PATH_SEP);
|
p = strrchr (param_basename, PATH_SEP);
|
||||||
if (!p)
|
if (p == NULL)
|
||||||
p = param_basename;
|
p = param_basename;
|
||||||
else
|
else
|
||||||
p++;
|
p++;
|
||||||
@ -193,20 +193,16 @@ vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_b
|
|||||||
if (shift > 0)
|
if (shift > 0)
|
||||||
p += shift;
|
p += shift;
|
||||||
|
|
||||||
suffix = g_malloc (MC_MAXPATHLEN);
|
suffix = g_string_sized_new (32);
|
||||||
|
|
||||||
/* Protection against unusual characters */
|
/* Protection against unusual characters */
|
||||||
q = suffix;
|
for (; *p != '\0' && *p != '#'; p++)
|
||||||
while (*p && (*p != '#'))
|
if (strchr (".-_@", *p) != NULL || g_ascii_isalnum (*p))
|
||||||
{
|
g_string_append_c (suffix, *p);
|
||||||
if (strchr (".-_@", *p) || isalnum ((unsigned char) *p))
|
|
||||||
*q++ = *p;
|
fd = mc_mkstemps (pname_vpath, prefix, suffix->str);
|
||||||
p++;
|
g_string_free (suffix, TRUE);
|
||||||
}
|
|
||||||
*q = 0;
|
|
||||||
|
|
||||||
fd = mc_mkstemps (pname_vpath, prefix, suffix);
|
|
||||||
g_free (suffix);
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user