remove str(n)dupa usages

str(n)dupa are GNU extensions that duplicate a string, using an alloca'd
buffer. This patch removes their definitions from e.h (which should only
contain E's own API, without fallback definitions for libc functions)
which were wrong anyway (they failed in cases where str(n)dupa was an
actual function, not a macro).

Instead, we replace them depending on context with alloca+memcpy+strlen
or a static buffer (used in contexts where we are sure that the buffer
will contain the string entirely)

@fix
This commit is contained in:
Daniel Kolesa 2015-05-11 16:33:42 +01:00
parent 413463d2cd
commit 82116f63ab
10 changed files with 41 additions and 47 deletions

View File

@ -169,14 +169,6 @@ void *alloca (size_t);
# define EINTERN # define EINTERN
# endif # endif
#ifndef strdupa
# define strdupa(str) strcpy(alloca(strlen(str) + 1), str)
#endif
#ifndef strndupa
# define strndupa(str, len) strncpy(alloca(len + 1), str, len)
#endif
typedef struct _E_Before_Idler E_Before_Idler; typedef struct _E_Before_Idler E_Before_Idler;
typedef struct _E_Rect E_Rect; typedef struct _E_Rect E_Rect;

View File

@ -1926,8 +1926,10 @@ ACT_FN_GO(app, )
{ {
Efreet_Desktop *desktop = NULL; Efreet_Desktop *desktop = NULL;
char *p, *p2; char *p, *p2;
size_t plen;
p2 = strdupa(params); plen = strlen(params);
p2 = memcpy(alloca(plen + 1), params, plen + 1);
p = strchr(p2, ':'); p = strchr(p2, ':');
if (p) if (p)
{ {

View File

@ -1448,9 +1448,10 @@ E_API void
e_fm2_parent_go(Evas_Object *obj) e_fm2_parent_go(Evas_Object *obj)
{ {
char *p, *path; char *p, *path;
char buf[PATH_MAX];
EFM_SMART_CHECK(); EFM_SMART_CHECK();
if (!sd->path) return; if (!sd->path) return;
path = strdupa(sd->path); path = memcpy(buf, sd->path, strlen(sd->path + 1));
if ((p = strrchr(path, '/'))) *p = 0; if ((p = strrchr(path, '/'))) *p = 0;
if (*path) if (*path)
e_fm2_path_set(obj, sd->dev, path); e_fm2_path_set(obj, sd->dev, path);
@ -5866,7 +5867,10 @@ _e_fm2_typebuf_match(Evas_Object *obj, int next)
tb[tblen + 1] = '\0'; tb[tblen + 1] = '\0';
} }
else else
tb = strdupa(sd->typebuf.buf); {
size_t blen = strlen(sd->typebuf.buf);
tb = memcpy(alloca(blen + 1), sd->typebuf.buf, blen + 1);
}
if (!next) if (!next)
{ {

View File

@ -44,10 +44,6 @@
#include "e_fm_shared_codec.h" #include "e_fm_shared_codec.h"
#define DEF_MOD_BACKOFF 0.2 #define DEF_MOD_BACKOFF 0.2
#ifndef strdupa
# define strdupa(str) strcpy(alloca(strlen(str) + 1), str)
#endif
typedef struct _E_Dir E_Dir; typedef struct _E_Dir E_Dir;
typedef struct _E_Fop E_Fop; typedef struct _E_Fop E_Fop;
typedef struct _E_Mod E_Mod; typedef struct _E_Mod E_Mod;
@ -1160,8 +1156,8 @@ _e_fm_ipc_cb_fop_trash_idler(void *data)
FILE *info = NULL; FILE *info = NULL;
const char *filename; const char *filename;
const char *escname = NULL; const char *escname = NULL;
char *dest, *trash_dir; char *dest;
char buf[4096]; char buf[4096], trash_dir[4096];
unsigned int i = 0; unsigned int i = 0;
struct tm *lt; struct tm *lt;
time_t t; time_t t;
@ -1173,8 +1169,7 @@ _e_fm_ipc_cb_fop_trash_idler(void *data)
if (!fop) return 0; if (!fop) return 0;
/* Check that 'home trash' and subsequesnt dirs exists, create if not */ /* Check that 'home trash' and subsequesnt dirs exists, create if not */
snprintf(buf, sizeof(buf), "%s/Trash", efreet_data_home_get()); snprintf(trash_dir, sizeof(trash_dir), "%s/Trash", efreet_data_home_get());
trash_dir = strdupa(buf);
snprintf(buf, sizeof(buf), "%s/files", trash_dir); snprintf(buf, sizeof(buf), "%s/files", trash_dir);
if (!ecore_file_mkpath(buf)) return 0; if (!ecore_file_mkpath(buf)) return 0;
snprintf(buf, sizeof(buf), "%s/info", trash_dir); snprintf(buf, sizeof(buf), "%s/info", trash_dir);

View File

@ -44,10 +44,6 @@ void *alloca(size_t);
#undef E_TYPEDEFS #undef E_TYPEDEFS
#include "e_fm_op.h" #include "e_fm_op.h"
#ifndef strdupa
# define strdupa(str) strcpy(alloca(strlen(str) + 1), str)
#endif
#define READBUFSIZE 65536 #define READBUFSIZE 65536
#define COPYBUFSIZE 16384 #define COPYBUFSIZE 16384
#define REMOVECHUNKSIZE 4096 #define REMOVECHUNKSIZE 4096
@ -1282,6 +1278,7 @@ static int
_e_fm_op_copy_link(E_Fm_Op_Task *task) _e_fm_op_copy_link(E_Fm_Op_Task *task)
{ {
char *lnk_path; char *lnk_path;
size_t lnk_len;
lnk_path = ecore_file_readlink(task->src.name); lnk_path = ecore_file_readlink(task->src.name);
if (!lnk_path) if (!lnk_path)
@ -1289,6 +1286,8 @@ _e_fm_op_copy_link(E_Fm_Op_Task *task)
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot read link '%s'.", task->src.name); _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot read link '%s'.", task->src.name);
} }
lnk_len = strlen(lnk_path);
E_FM_OP_DEBUG("Creating link from '%s' to '%s'\n", lnk_path, task->dst.name); E_FM_OP_DEBUG("Creating link from '%s' to '%s'\n", lnk_path, task->dst.name);
_e_fm_op_update_progress_report_simple(0, lnk_path, task->dst.name); _e_fm_op_update_progress_report_simple(0, lnk_path, task->dst.name);
@ -1305,14 +1304,14 @@ _e_fm_op_copy_link(E_Fm_Op_Task *task)
} }
if (symlink(lnk_path, task->dst.name) == -1) if (symlink(lnk_path, task->dst.name) == -1)
{ {
buf = strdupa(lnk_path); buf = memcpy(alloca(lnk_len + 1), lnk_path, lnk_len + 1);
free(lnk_path); free(lnk_path);
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", buf, task->dst.name); _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", buf, task->dst.name);
} }
} }
else else
{ {
buf = strdupa(lnk_path); buf = memcpy(alloca(lnk_len + 1), lnk_path, lnk_len + 1);
free(lnk_path); free(lnk_path);
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", buf, task->dst.name); _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", buf, task->dst.name);
} }

View File

@ -19,7 +19,7 @@ _import_edj_gen(E_Import_Config_Dialog *import)
int fd, num = 1; int fd, num = 1;
int w = 0, h = 0; int w = 0, h = 0;
const char *file, *locale; const char *file, *locale;
char buf[PATH_MAX], cmd[PATH_MAX], tmpn[PATH_MAX], ipart[PATH_MAX], enc[128]; char buf[PATH_MAX], fbuf[PATH_MAX], cmd[PATH_MAX], tmpn[PATH_MAX], ipart[PATH_MAX], enc[128];
Eina_Tmpstr *path = NULL; Eina_Tmpstr *path = NULL;
char *imgdir = NULL, *fstrip; char *imgdir = NULL, *fstrip;
int cr, cg, cb, ca; int cr, cg, cb, ca;
@ -82,12 +82,14 @@ _import_edj_gen(E_Import_Config_Dialog *import)
if (import->external) if (import->external)
{ {
fstrip = strdupa(e_util_filename_escape(import->file)); const char *esc = e_util_filename_escape(import->file);
fstrip = memcpy(fbuf, esc, strlen(esc) + 1);
snprintf(enc, sizeof(enc), "USER"); snprintf(enc, sizeof(enc), "USER");
} }
else else
{ {
fstrip = strdupa(e_util_filename_escape(file)); const char *esc = e_util_filename_escape(file);
fstrip = memcpy(fbuf, esc, strlen(esc) + 1);
if (import->quality == 100) if (import->quality == 100)
snprintf(enc, sizeof(enc), "COMP"); snprintf(enc, sizeof(enc), "COMP");
else else

View File

@ -536,7 +536,8 @@ _e_intl_locale_alias_get(const char *language)
{ {
Eina_Hash *alias_hash; Eina_Hash *alias_hash;
char *alias; char *alias;
char *lower_language; char llbuf[256];
char *lower_language = llbuf;
if ((!language) || (!strncmp(language, "POSIX", strlen("POSIX")))) if ((!language) || (!strncmp(language, "POSIX", strlen("POSIX"))))
return strdup("C"); return strdup("C");
@ -545,9 +546,8 @@ _e_intl_locale_alias_get(const char *language)
if (!alias_hash) /* No alias file available */ if (!alias_hash) /* No alias file available */
return strdup(language); return strdup(language);
lower_language = strdupa(language); strcpy(lower_language, language);
eina_str_tolower(&lower_language); eina_str_tolower(&lower_language);
alias = eina_hash_find(alias_hash, lower_language); alias = eina_hash_find(alias_hash, lower_language);
if (alias) if (alias)

View File

@ -41,8 +41,10 @@ e_theme_collection_items_find(const char *base EINA_UNUSED, const char *collname
EINA_LIST_FREE(list, s) EINA_LIST_FREE(list, s)
{ {
char *trans, *p, *p2; char *trans, *p, *p2;
size_t slen;
trans = strdupa(s); slen = strlen(s);
trans = memcpy(alloca(slen + 1), s, slen + 1);
p = trans + len + 1; p = trans + len + 1;
if (*p) if (*p)
{ {

View File

@ -227,10 +227,11 @@ _basic_create_widgets(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dia
{ {
char *p; char *p;
const char *pp; const char *pp;
char buf[PATH_MAX];
pp = strchr(s, '/'); pp = strchr(s, '/');
pp = pp ? pp + 1 : s; pp = pp ? pp + 1 : s;
p = strdupa(pp); p = memcpy(buf, pp, strlen(pp) + 1);
p[0] = toupper(p[0]); p[0] = toupper(p[0]);
ob = e_widget_radio_add(evas, _(p), mode, rg); ob = e_widget_radio_add(evas, _(p), mode, rg);
e_widget_list_object_append(o, ob, 1, 0, 0.5); e_widget_list_object_append(o, ob, 1, 0, 0.5);

View File

@ -7,13 +7,11 @@ static Evas_Object *textblock = NULL;
static void static void
_profile_change(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED) _profile_change(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX], buf2[PATH_MAX];
char *dir;
Efreet_Desktop *desk = NULL; Efreet_Desktop *desk = NULL;
e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", profile); e_prefix_data_snprintf(buf2, sizeof(buf2), "data/config/%s", profile);
dir = strdupa(buf); snprintf(buf, sizeof(buf), "%s/profile.desktop", buf2);
snprintf(buf, sizeof(buf), "%s/profile.desktop", dir);
desk = efreet_desktop_new(buf); desk = efreet_desktop_new(buf);
if (desk) if (desk)
{ {
@ -62,8 +60,8 @@ wizard_page_show(E_Wizard_Page *pg)
for (i = 0, l = profiles; l; l = l->next) for (i = 0, l = profiles; l; l = l->next)
{ {
Efreet_Desktop *desk = NULL; Efreet_Desktop *desk = NULL;
char buf[PATH_MAX], *prof; char buf[PATH_MAX], buf2[PATH_MAX], *prof;
const char *label, *dir; const char *label;
Evas_Object *ic; Evas_Object *ic;
prof = l->data; prof = l->data;
@ -75,26 +73,25 @@ wizard_page_show(E_Wizard_Page *pg)
continue; continue;
} }
} }
e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s", prof); e_prefix_data_snprintf(buf2, sizeof(buf2), "data/config/%s", prof);
// if it's not a system profile - don't offer it // if it's not a system profile - don't offer it
if (!ecore_file_is_dir(buf)) if (!ecore_file_is_dir(buf2))
{ {
free(prof); free(prof);
continue; continue;
} }
dir = strdupa(buf);
if (!strcmp(prof, "standard")) sel = i; if (!strcmp(prof, "standard")) sel = i;
snprintf(buf, sizeof(buf), "%s/profile.desktop", dir); snprintf(buf, sizeof(buf), "%s/profile.desktop", buf2);
desk = efreet_desktop_new(buf); desk = efreet_desktop_new(buf);
label = prof; label = prof;
if ((desk) && (desk->name)) label = desk->name; if ((desk) && (desk->name)) label = desk->name;
snprintf(buf, sizeof(buf), "%s/icon.edj", dir); snprintf(buf, sizeof(buf), "%s/icon.edj", buf2);
if ((desk) && (desk->icon)) if ((desk) && (desk->icon))
{ {
if (eina_str_has_extension(desk->icon, "png")) if (eina_str_has_extension(desk->icon, "png"))
snprintf(buf, sizeof(buf), "%s/%s", dir, desk->icon); snprintf(buf, sizeof(buf), "%s/%s", buf2, desk->icon);
else else
snprintf(buf, sizeof(buf), "%s/%s.png", dir, desk->icon); snprintf(buf, sizeof(buf), "%s/%s.png", buf2, desk->icon);
} }
else else
e_prefix_data_concat_static(buf, "data/images/enlightenment.png"); e_prefix_data_concat_static(buf, "data/images/enlightenment.png");