Use strlcpy
authorSebastian Dransfeld <sd@tango.flipp.net>
Mon, 27 Oct 2008 12:34:35 +0000 (12:34 +0000)
committerSebastian Dransfeld <sd@tango.flipp.net>
Mon, 27 Oct 2008 12:34:35 +0000 (12:34 +0000)
SVN revision: 37237

15 files changed:
src/bin/e.h
src/bin/e_actions.c
src/bin/e_desklock.c
src/bin/e_eap_editor.c
src/bin/e_fm.c
src/bin/e_fm_mime.c
src/bin/e_prefix.c
src/bin/e_start_main.c
src/bin/e_theme.c
src/modules/conf_theme/e_int_config_theme.c
src/modules/exebuf/e_exebuf.c
src/modules/ibar/e_mod_main.c
src/modules/illume/e_mod_win.c
src/modules/illume/wifiget.c
src/modules/wizard/page_030.c

index 3f42144..0b6970f 100644 (file)
@@ -64,6 +64,7 @@
 #include <Evas.h>
 #include <Evas_Engine_Buffer.h>
 #include <Ecore.h>
+#include <Ecore_Str.h>
 #include <Ecore_X.h>
 #include <Ecore_X_Atoms.h>
 #include <Ecore_X_Cursor.h>
index b25115a..7e9e9d1 100644 (file)
@@ -2148,15 +2148,13 @@ _delayed_action_list_parse(Delayed_Action *da, const char *params)
        const char *action, *params;
        
        a1 = alloca(a1stop - a1start + 1);
-       strncpy(a1, a1start, a1stop - a1start);
-       a1[a1stop - a1start] = 0;
+       ecore_strlcpy(a1, a1start, a1stop - a1start + 1);
        action = NULL;
        params = NULL;
        _delayed_action_list_parse_action(a1, &delay, &da->def.action, &da->def.params);
        
        a2 = alloca(a1stop - a1start + 1);
-       strncpy(a2, a2start, a2stop - a2start);
-       a2[a2stop - a2start] = 0;
+       ecore_strlcpy(a2, a2start, a2stop - a2start + 1);
        _delayed_action_list_parse_action(a2, &delay, &da->delayed.action, &da->delayed.params);
      }
    da->timer = ecore_timer_add(delay, _delayed_action_cb_timer, da);
index 1acefef..1044e10 100644 (file)
@@ -701,8 +701,8 @@ _desklock_auth(char *passwd)
        sigaction(SIGABRT, &action, NULL);
        
        current_user = _desklock_auth_get_current_user();
-       strncpy(da.user, current_user, PATH_MAX);
-       strncpy(da.passwd, passwd, PATH_MAX);
+       ecore_strlcpy(da.user, current_user, PATH_MAX);
+       ecore_strlcpy(da.passwd, passwd, PATH_MAX);
        /* security - null out passwd string once we are done with it */
        for (p = passwd; *p; p++) *p = 0;
        da.pam.handle = NULL;
index 1280d05..4621ed4 100644 (file)
@@ -402,7 +402,7 @@ _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfd
             basename[i] = '\0';
          }
        else
-         strncpy(basename, "unnamed_desktop", sizeof(basename));
+         ecore_strlcpy(basename, "unnamed_desktop", sizeof(basename));
 
        i = 0;
        snprintf(path, sizeof(path), "%s/applications/%s.desktop", 
index 175466f..a92f5d3 100644 (file)
@@ -3738,9 +3738,8 @@ _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
         * more is considered part of the name
         */
-       strncpy(buf, ic->info.file, sizeof(buf) - 2);
-       buf[sizeof(buf) - 1] = 0;
-       
+       ecore_strlcpy(buf, ic->info.file, sizeof(buf));
+
        len = strlen(buf);
        p = strrchr(buf, '.');
        if ((p) && ((len - (p - buf)) < 6))
@@ -5962,10 +5961,8 @@ _e_fm2_cb_icon_sort(const void *data1, const void *data2)
          }
        else
 */       {
-            strncpy(buf1, l1, sizeof(buf1) - 2);
-            strncpy(buf2, l2, sizeof(buf2) - 2);
-            buf1[sizeof(buf1) - 1] = 0;
-            buf2[sizeof(buf2) - 1] = 0;
+            ecore_strlcpy(buf1, l1, sizeof(buf1));
+            ecore_strlcpy(buf2, l2, sizeof(buf2));
          }
        p = buf1;
        while (*p)
index 3423d5e..3a98dfa 100644 (file)
@@ -48,8 +48,7 @@ e_fm_mime_icon_get(const char *mime)
    val = evas_hash_find(icon_map, mime);
    if (val) return val;
    
-   strncpy(buf2, mime, sizeof(buf2) - 1);
-   buf2[sizeof(buf2) - 1] = 0;
+   ecore_strlcpy(buf2, mime, sizeof(buf2));
    val = strchr(buf2, '/');
    if (val) *val = 0;
    
@@ -59,8 +58,7 @@ e_fm_mime_icon_get(const char *mime)
        mi = l->data;
        if (e_util_glob_match(mi->mime, mime))
          {
-            strncpy(buf, mi->icon, sizeof(buf) - 1);
-            buf[sizeof(buf) - 1] = 0;
+            ecore_strlcpy(buf, mi->icon, sizeof(buf));
             goto ok;
          }
      }
index 6b0aeca..dac1b13 100644 (file)
@@ -91,8 +91,7 @@ e_prefix_determine(char *argv0)
                  _prefix_path = malloc(p - _exe_path + 1);
                  if (_prefix_path)
                    {
-                      strncpy(_prefix_path, _exe_path, p - _exe_path);
-                      _prefix_path[p - _exe_path] = 0;
+                      ecore_strlcpy(_prefix_path, _exe_path, p - _exe_path + 1);
 
                       /* bin and lib always together */
                       snprintf(buf, sizeof(buf), "%s/bin", _prefix_path);
index da6cd0a..c299b08 100644 (file)
@@ -84,8 +84,7 @@ prefix_determine(char *argv0)
                  _prefix_path = malloc(p - _exe_path + 1);
                  if (_prefix_path)
                    {
-                      strncpy(_prefix_path, _exe_path, p - _exe_path);
-                      _prefix_path[p - _exe_path] = 0;
+                      strlcpy(_prefix_path, _exe_path, p - _exe_path + 1);
                       return 1;
                    }
                  else
index b20dc59..32137dd 100644 (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 */
-   strncpy(buf, category, sizeof(buf) - 1);
-   buf[sizeof(buf) - 1] = 0;
+   ecore_strlcpy(buf, category, sizeof(buf));
    /* shorten string up to and not including last / char */
    p = strrchr(buf, '/');
    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 */
-   strncpy(buf, category, sizeof(buf) - 1);
-   buf[sizeof(buf) - 1] = 0;
+   ecore_strlcpy(buf, category, sizeof(buf));
    /* shorten string up to and not including last / char */
    p = strrchr(buf, '/');
    if (p) *p = 0;
index 63394d8..d7e6450 100644 (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");
               }
             tmp = strdup(strrchr(themefiles->data, '/') + 1);
-            strncpy(themename, tmp, strlen(tmp)-3);
-            themename[strlen(tmp)-4] = '\0';
+            strncpy(themename, tmp, strlen(tmp) - 3);
+            themename[strlen(tmp) - 4] = '\0';
             e_widget_ilist_append(o, ic, themename, NULL, NULL, NULL);
             free(tmp);
 
index dd809c7..2fdbec5 100644 (file)
@@ -757,15 +757,13 @@ _e_exebuf_complete(void)
             exe = ecore_file_app_exe_get(exe_sel->desktop->exec);
             if (exe)
               {
-                 strncpy(cmd_buf, exe, EXEBUFLEN - 1);
-                 cmd_buf[EXEBUFLEN - 1] = 0;
+                 ecore_strlcpy(cmd_buf, exe, EXEBUFLEN);
                  free(exe);
               }
          }
        else if (exe_sel->file)
          {
-            strncpy(cmd_buf, exe_sel->file, EXEBUFLEN - 1);
-            cmd_buf[EXEBUFLEN - 1] = 0;
+            ecore_strlcpy(cmd_buf, exe_sel->file, EXEBUFLEN);
          }
      }
    else
@@ -805,8 +803,7 @@ _e_exebuf_complete(void)
      }
    if ((exe) && (orig_len < common_len) && (common_len < (EXEBUFLEN - 1)))
      {
-       strncpy(cmd_buf, exe, common_len);
-       cmd_buf[common_len] = 0;
+       ecore_strlcpy(cmd_buf, exe, common_len + 1);
      }
    if (clear_hist)
      _e_exebuf_hist_clear();
index e7d88d7..c04afff 100644 (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);
      }
    else
-     snprintf(buf, sizeof(buf), inst->ci->dir);
+     ecore_strlcpy(buf, inst->ci->dir, sizeof(buf));
    b->apps = e_order_new(buf);
    e_order_update_callback_set(b->apps, _ibar_cb_app_change, 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);
          }
        else
-         snprintf(buf, sizeof(buf), inst->ci->dir);
+         ecore_strlcpy(buf, inst->ci->dir, sizeof(buf));
        inst->ibar->apps = e_order_new(buf);
        _ibar_fill(inst->ibar);
        _ibar_resize_handle(inst->ibar);
index 97a7643..b0f4a22 100644 (file)
@@ -359,8 +359,7 @@ _desktop_run(Efreet_Desktop *desktop)
        exename = malloc(p - desktop->exec + 1);
        if (exename)
          {
-            strncpy(exename, desktop->exec, p - desktop->exec);
-            exename[p - desktop->exec] = 0;
+            ecore_strlcpy(exename, desktop->exec, p - desktop->exec + 1);
          }
      }
    if (exename)
index 4060b52..1bc74bd 100644 (file)
@@ -23,7 +23,7 @@
 static int
 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));
 }
 
index aaa2720..aa6707c 100644 (file)
@@ -121,8 +121,7 @@ wizard_page_show(E_Wizard_Page *pg)
                            tlabel = malloc(p2 - p + 1);
                            if (tlabel)
                              {
-                                strncpy(tlabel, p, p2 - p);
-                                tlabel[p2 - p] = 0;
+                                ecore_strlcpy(tlabel, p, p2 - p + 1);
                                 tlabel[0] = toupper(tlabel[0]);
                                 if (*p2 == '-')
                                   {
@@ -133,8 +132,7 @@ wizard_page_show(E_Wizard_Page *pg)
                                           tdesc = malloc(p - p2 + 1);
                                           if (tdesc)
                                             {
-                                               strncpy(tdesc, p2, p - p2);
-                                               tdesc[p - p2] = 0;
+                                               ecore_strlcpy(tdesc, p2, p - p2 + 1);
                                                tdesc[0] = toupper(tdesc[0]);
                                                snprintf(buf, sizeof(buf), "%s (%s)", tlabel, tdesc);
                                             }