efreet: use alloca for local dynamic buffer

SVN revision: 47597
This commit is contained in:
Sebastian Dransfeld 2010-03-30 12:22:15 +00:00
parent 1b6662b2e9
commit 6d00dc126b
4 changed files with 39 additions and 26 deletions

View File

@ -197,13 +197,15 @@ static int
efreet_parse_locale_setting(const char *env)
{
int found = 0;
char setting[PATH_MAX];
char *setting;
char *p;
size_t len;
p = getenv(env);
if (!p) return 0;
strncpy(setting, p, sizeof(setting));
setting[PATH_MAX - 1] = '\0';
len = strlen(p) + 1;
setting = alloca(len);
memcpy(setting, p, len);
/* pull the modifier off the end */
p = strrchr(setting, '@');

View File

@ -226,15 +226,17 @@ efreet_dirs_get(const char *key, const char *fallback)
{
Eina_List *dirs = NULL;
const char *path;
char tmp[PATH_MAX], *s, *p;
char *tmp, *s, *p;
size_t len;
path = getenv(key);
if (!path || (path[0] == '\0')) path = fallback;
if (!path) return dirs;
strncpy(tmp, path, sizeof(tmp));
tmp[PATH_MAX - 1] = '\0';
len = strlen(path) + 1;
tmp = alloca(len);
memcpy(tmp, path, len);
s = tmp;
p = strchr(s, EFREET_PATH_SEP);
while (p)

View File

@ -948,7 +948,7 @@ efreet_menu_dump(Efreet_Menu *menu, const char *indent)
{
Efreet_Menu *entry;
char *new_indent;
int len;
size_t len;
len = strlen(indent) + 3;
new_indent = malloc(sizeof(char *) * len);
@ -1781,7 +1781,7 @@ static int
efreet_menu_handle_default_merge_dirs(Efreet_Menu_Internal *parent, Efreet_Xml *xml)
{
Eina_List *dirs;
char path[PATH_MAX], p[128], *pp;
char path[PATH_MAX], *p, *pp;
#ifndef STRICT_SPEC
char parent_path[PATH_MAX];
#endif
@ -1793,21 +1793,23 @@ efreet_menu_handle_default_merge_dirs(Efreet_Menu_Internal *parent, Efreet_Xml *
if (!strcmp(prefix, "gnome-") &&
(!strcmp(parent->file.name, "gnome-applications.menu")))
{
strncpy(p, "applications", 128);
p[128 - 1] = '\0';
p = alloca(sizeof("applications"));
memcpy(p, "applications", sizeof("applications"));
}
else if ((!strcmp(prefix, "kde-") &&
(!strcmp(parent->file.name, "kde-applications.menu"))))
{
strncpy(p, "applications", 128);
p[128 - 1] = '\0';
p = alloca(sizeof("applications"));
memcpy(p, "applications", sizeof("applications"));
}
else
{
char *s;
size_t len;
strncpy(p, parent->file.name, 128);
p[128 - 1] = '\0';
len = strlen(parent->file.name) + 1;
p = alloca(len);
memcpy(p, parent->file.name, len);
s = strrchr(p, '.');
if (s) *s = '\0';
}
@ -3100,12 +3102,14 @@ efreet_menu_resolve_moves(Efreet_Menu_Internal *internal)
dest = efreet_menu_by_name_find(internal, move->new_name, &parent);
if (!dest)
{
char *path, *tmp, t[PATH_MAX];
char *path, *tmp, *t;
size_t len;
/* if the dest path has /'s in it then we need to add menus to
* fill out the paths */
strncpy(t, move->new_name, PATH_MAX);
t[PATH_MAX - 1] = '\0';
len = strlen(move->new_name) + 1;
t = alloca(len);
memcpy(t, move->new_name, len);
tmp = t;
path = strchr(tmp, '/');
while (path)
@ -3152,13 +3156,15 @@ efreet_menu_resolve_moves(Efreet_Menu_Internal *internal)
static Efreet_Menu_Internal *
efreet_menu_by_name_find(Efreet_Menu_Internal *internal, const char *name, Efreet_Menu_Internal **parent)
{
char *part, tmp[PATH_MAX], *ptr;
char *part, *tmp, *ptr;
size_t len;
if (parent) *parent = internal;
/* find the correct parent menu */
strncpy(tmp, name, PATH_MAX);
tmp[PATH_MAX - 1] = '\0';
len = strlen(name) + 1;
tmp = alloca(len);
memcpy(tmp, name, len);
ptr = tmp;
part = strchr(ptr, '/');
while (part)
@ -3192,10 +3198,12 @@ efreet_menu_by_name_find(Efreet_Menu_Internal *internal, const char *name, Efree
static void
efreet_menu_path_set(Efreet_Menu_Internal *internal, const char *path)
{
char tmp[PATH_MAX], *p;
char *tmp, *p;
size_t len;
strncpy(tmp, path, PATH_MAX);
tmp[PATH_MAX - 1] = '\0';
len = strlen(path) + 1;
tmp = alloca(len);
memcpy(tmp, path, len);
p = strrchr(tmp, '/');
if (p)
{

View File

@ -124,7 +124,7 @@ EAPI const char *
efreet_util_path_to_file_id(const char *path)
{
size_t len;
char tmp[PATH_MAX], *p;
char *tmp, *p;
char *base;
const char *file_id;
@ -148,8 +148,9 @@ efreet_util_path_to_file_id(const char *path)
return NULL;
}
strncpy(tmp, path + len + 1, sizeof(tmp));
tmp[PATH_MAX - 1] = '\0';
len = strlen(path + len + 1) + 1;
tmp = alloca(len);
memcpy(tmp, path + len + 1, len);
p = tmp;
while (*p)
{