Use strlcpy

SVN revision: 37237
This commit is contained in:
Sebastian Dransfeld 2008-10-27 12:34:35 +00:00
parent ac31380ee0
commit 10396e6085
15 changed files with 27 additions and 43 deletions

View File

@ -64,6 +64,7 @@
#include <Evas.h> #include <Evas.h>
#include <Evas_Engine_Buffer.h> #include <Evas_Engine_Buffer.h>
#include <Ecore.h> #include <Ecore.h>
#include <Ecore_Str.h>
#include <Ecore_X.h> #include <Ecore_X.h>
#include <Ecore_X_Atoms.h> #include <Ecore_X_Atoms.h>
#include <Ecore_X_Cursor.h> #include <Ecore_X_Cursor.h>

View File

@ -2148,15 +2148,13 @@ _delayed_action_list_parse(Delayed_Action *da, const char *params)
const char *action, *params; const char *action, *params;
a1 = alloca(a1stop - a1start + 1); a1 = alloca(a1stop - a1start + 1);
strncpy(a1, a1start, a1stop - a1start); ecore_strlcpy(a1, a1start, a1stop - a1start + 1);
a1[a1stop - a1start] = 0;
action = NULL; action = NULL;
params = NULL; params = NULL;
_delayed_action_list_parse_action(a1, &delay, &da->def.action, &da->def.params); _delayed_action_list_parse_action(a1, &delay, &da->def.action, &da->def.params);
a2 = alloca(a1stop - a1start + 1); a2 = alloca(a1stop - a1start + 1);
strncpy(a2, a2start, a2stop - a2start); ecore_strlcpy(a2, a2start, a2stop - a2start + 1);
a2[a2stop - a2start] = 0;
_delayed_action_list_parse_action(a2, &delay, &da->delayed.action, &da->delayed.params); _delayed_action_list_parse_action(a2, &delay, &da->delayed.action, &da->delayed.params);
} }
da->timer = ecore_timer_add(delay, _delayed_action_cb_timer, da); da->timer = ecore_timer_add(delay, _delayed_action_cb_timer, da);

View File

@ -701,8 +701,8 @@ _desklock_auth(char *passwd)
sigaction(SIGABRT, &action, NULL); sigaction(SIGABRT, &action, NULL);
current_user = _desklock_auth_get_current_user(); current_user = _desklock_auth_get_current_user();
strncpy(da.user, current_user, PATH_MAX); ecore_strlcpy(da.user, current_user, PATH_MAX);
strncpy(da.passwd, passwd, PATH_MAX); ecore_strlcpy(da.passwd, passwd, PATH_MAX);
/* security - null out passwd string once we are done with it */ /* security - null out passwd string once we are done with it */
for (p = passwd; *p; p++) *p = 0; for (p = passwd; *p; p++) *p = 0;
da.pam.handle = NULL; da.pam.handle = NULL;

View File

@ -402,7 +402,7 @@ _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfd
basename[i] = '\0'; basename[i] = '\0';
} }
else else
strncpy(basename, "unnamed_desktop", sizeof(basename)); ecore_strlcpy(basename, "unnamed_desktop", sizeof(basename));
i = 0; i = 0;
snprintf(path, sizeof(path), "%s/applications/%s.desktop", snprintf(path, sizeof(path), "%s/applications/%s.desktop",

View File

@ -3738,8 +3738,7 @@ _e_fm2_icon_label_set(E_Fm2_Icon *ic, Evas_Object *obj)
* also be fuzzy - up to 4 chars of extn is ok - eg .html but 5 or * also be fuzzy - up to 4 chars of extn is ok - eg .html but 5 or
* more is considered part of the name * more is considered part of the name
*/ */
strncpy(buf, ic->info.file, sizeof(buf) - 2); ecore_strlcpy(buf, ic->info.file, sizeof(buf));
buf[sizeof(buf) - 1] = 0;
len = strlen(buf); len = strlen(buf);
p = strrchr(buf, '.'); p = strrchr(buf, '.');
@ -5962,10 +5961,8 @@ _e_fm2_cb_icon_sort(const void *data1, const void *data2)
} }
else else
*/ { */ {
strncpy(buf1, l1, sizeof(buf1) - 2); ecore_strlcpy(buf1, l1, sizeof(buf1));
strncpy(buf2, l2, sizeof(buf2) - 2); ecore_strlcpy(buf2, l2, sizeof(buf2));
buf1[sizeof(buf1) - 1] = 0;
buf2[sizeof(buf2) - 1] = 0;
} }
p = buf1; p = buf1;
while (*p) while (*p)

View File

@ -48,8 +48,7 @@ e_fm_mime_icon_get(const char *mime)
val = evas_hash_find(icon_map, mime); val = evas_hash_find(icon_map, mime);
if (val) return val; if (val) return val;
strncpy(buf2, mime, sizeof(buf2) - 1); ecore_strlcpy(buf2, mime, sizeof(buf2));
buf2[sizeof(buf2) - 1] = 0;
val = strchr(buf2, '/'); val = strchr(buf2, '/');
if (val) *val = 0; if (val) *val = 0;
@ -59,8 +58,7 @@ e_fm_mime_icon_get(const char *mime)
mi = l->data; mi = l->data;
if (e_util_glob_match(mi->mime, mime)) if (e_util_glob_match(mi->mime, mime))
{ {
strncpy(buf, mi->icon, sizeof(buf) - 1); ecore_strlcpy(buf, mi->icon, sizeof(buf));
buf[sizeof(buf) - 1] = 0;
goto ok; goto ok;
} }
} }

View File

@ -91,8 +91,7 @@ e_prefix_determine(char *argv0)
_prefix_path = malloc(p - _exe_path + 1); _prefix_path = malloc(p - _exe_path + 1);
if (_prefix_path) if (_prefix_path)
{ {
strncpy(_prefix_path, _exe_path, p - _exe_path); ecore_strlcpy(_prefix_path, _exe_path, p - _exe_path + 1);
_prefix_path[p - _exe_path] = 0;
/* bin and lib always together */ /* bin and lib always together */
snprintf(buf, sizeof(buf), "%s/bin", _prefix_path); snprintf(buf, sizeof(buf), "%s/bin", _prefix_path);

View File

@ -84,8 +84,7 @@ prefix_determine(char *argv0)
_prefix_path = malloc(p - _exe_path + 1); _prefix_path = malloc(p - _exe_path + 1);
if (_prefix_path) if (_prefix_path)
{ {
strncpy(_prefix_path, _exe_path, p - _exe_path); strlcpy(_prefix_path, _exe_path, p - _exe_path + 1);
_prefix_path[p - _exe_path] = 0;
return 1; return 1;
} }
else else

View File

@ -197,8 +197,7 @@ e_theme_edje_object_set(Evas_Object *o, const char *category, const char *group)
} }
} }
/* no mapping or set failed - fall back */ /* no mapping or set failed - fall back */
strncpy(buf, category, sizeof(buf) - 1); ecore_strlcpy(buf, category, sizeof(buf));
buf[sizeof(buf) - 1] = 0;
/* shorten string up to and not including last / char */ /* shorten string up to and not including last / char */
p = strrchr(buf, '/'); p = strrchr(buf, '/');
if (p) *p = 0; if (p) *p = 0;
@ -277,8 +276,7 @@ e_theme_edje_file_get(const char *category, const char *group)
} }
} }
/* no mapping or set failed - fall back */ /* no mapping or set failed - fall back */
strncpy(buf, category, sizeof(buf) - 1); ecore_strlcpy(buf, category, sizeof(buf));
buf[sizeof(buf) - 1] = 0;
/* shorten string up to and not including last / char */ /* shorten string up to and not including last / char */
p = strrchr(buf, '/'); p = strrchr(buf, '/');
if (p) *p = 0; if (p) *p = 0;

View File

@ -758,8 +758,8 @@ _ilist_files_add(E_Config_Dialog_Data *cfdata, const char *header, const char *d
e_util_edje_icon_set(ic, "enlightenment/themes"); e_util_edje_icon_set(ic, "enlightenment/themes");
} }
tmp = strdup(strrchr(themefiles->data, '/') + 1); tmp = strdup(strrchr(themefiles->data, '/') + 1);
strncpy(themename, tmp, strlen(tmp)-3); strncpy(themename, tmp, strlen(tmp) - 3);
themename[strlen(tmp)-4] = '\0'; themename[strlen(tmp) - 4] = '\0';
e_widget_ilist_append(o, ic, themename, NULL, NULL, NULL); e_widget_ilist_append(o, ic, themename, NULL, NULL, NULL);
free(tmp); free(tmp);

View File

@ -757,15 +757,13 @@ _e_exebuf_complete(void)
exe = ecore_file_app_exe_get(exe_sel->desktop->exec); exe = ecore_file_app_exe_get(exe_sel->desktop->exec);
if (exe) if (exe)
{ {
strncpy(cmd_buf, exe, EXEBUFLEN - 1); ecore_strlcpy(cmd_buf, exe, EXEBUFLEN);
cmd_buf[EXEBUFLEN - 1] = 0;
free(exe); free(exe);
} }
} }
else if (exe_sel->file) else if (exe_sel->file)
{ {
strncpy(cmd_buf, exe_sel->file, EXEBUFLEN - 1); ecore_strlcpy(cmd_buf, exe_sel->file, EXEBUFLEN);
cmd_buf[EXEBUFLEN - 1] = 0;
} }
} }
else else
@ -805,8 +803,7 @@ _e_exebuf_complete(void)
} }
if ((exe) && (orig_len < common_len) && (common_len < (EXEBUFLEN - 1))) if ((exe) && (orig_len < common_len) && (common_len < (EXEBUFLEN - 1)))
{ {
strncpy(cmd_buf, exe, common_len); ecore_strlcpy(cmd_buf, exe, common_len + 1);
cmd_buf[common_len] = 0;
} }
if (clear_hist) if (clear_hist)
_e_exebuf_hist_clear(); _e_exebuf_hist_clear();

View File

@ -278,7 +278,7 @@ _ibar_new(Evas *evas, Instance *inst)
snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir); snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir);
} }
else else
snprintf(buf, sizeof(buf), inst->ci->dir); ecore_strlcpy(buf, inst->ci->dir, sizeof(buf));
b->apps = e_order_new(buf); b->apps = e_order_new(buf);
e_order_update_callback_set(b->apps, _ibar_cb_app_change, b); e_order_update_callback_set(b->apps, _ibar_cb_app_change, b);
_ibar_fill(b); _ibar_fill(b);
@ -506,7 +506,7 @@ _ibar_config_update(Config_Item *ci)
snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir); snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/%s/.order", homedir, inst->ci->dir);
} }
else else
snprintf(buf, sizeof(buf), inst->ci->dir); ecore_strlcpy(buf, inst->ci->dir, sizeof(buf));
inst->ibar->apps = e_order_new(buf); inst->ibar->apps = e_order_new(buf);
_ibar_fill(inst->ibar); _ibar_fill(inst->ibar);
_ibar_resize_handle(inst->ibar); _ibar_resize_handle(inst->ibar);

View File

@ -359,8 +359,7 @@ _desktop_run(Efreet_Desktop *desktop)
exename = malloc(p - desktop->exec + 1); exename = malloc(p - desktop->exec + 1);
if (exename) if (exename)
{ {
strncpy(exename, desktop->exec, p - desktop->exec); ecore_strlcpy(exename, desktop->exec, p - desktop->exec + 1);
exename[p - desktop->exec] = 0;
} }
} }
if (exename) if (exename)

View File

@ -23,7 +23,7 @@
static int static int
link_ext_get(int fd, const char *name, int req, struct iwreq *rq) link_ext_get(int fd, const char *name, int req, struct iwreq *rq)
{ {
strncpy(rq->ifr_name, name, sizeof(rq->ifr_name)); ecore_strlcpy(rq->ifr_name, name, sizeof(rq->ifr_name));
return (ioctl(fd, req, rq)); return (ioctl(fd, req, rq));
} }

View File

@ -121,8 +121,7 @@ wizard_page_show(E_Wizard_Page *pg)
tlabel = malloc(p2 - p + 1); tlabel = malloc(p2 - p + 1);
if (tlabel) if (tlabel)
{ {
strncpy(tlabel, p, p2 - p); ecore_strlcpy(tlabel, p, p2 - p + 1);
tlabel[p2 - p] = 0;
tlabel[0] = toupper(tlabel[0]); tlabel[0] = toupper(tlabel[0]);
if (*p2 == '-') if (*p2 == '-')
{ {
@ -133,8 +132,7 @@ wizard_page_show(E_Wizard_Page *pg)
tdesc = malloc(p - p2 + 1); tdesc = malloc(p - p2 + 1);
if (tdesc) if (tdesc)
{ {
strncpy(tdesc, p2, p - p2); ecore_strlcpy(tdesc, p2, p - p2 + 1);
tdesc[p - p2] = 0;
tdesc[0] = toupper(tdesc[0]); tdesc[0] = toupper(tdesc[0]);
snprintf(buf, sizeof(buf), "%s (%s)", tlabel, tdesc); snprintf(buf, sizeof(buf), "%s (%s)", tlabel, tdesc);
} }