[AD] Remove remaining occurences of ustrcpy()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This patch removes the few remaining occurences of ustrcpy() from the library 
code and replaces them by ustrzcpy(). ustrzcpy() is not less efficient than 
ustrcpy() and is safer.

Patch applied to trunk and branch.

-- 
Eric Botcazou
Index: src/config.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/config.c,v
retrieving revision 1.23
diff -u -r1.23 config.c
--- src/config.c	1 Nov 2002 11:55:30 -0000	1.23
+++ src/config.c	15 May 2003 21:08:29 -0000
@@ -919,7 +919,7 @@
       }
    }
 
-   ustrcpy(buf, s);
+   ustrzcpy(buf, buf_size, s);
    pos = 0;
    ac = 0;
 
Index: src/fsel.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fsel.c,v
retrieving revision 1.33
diff -u -r1.33 fsel.c
--- src/fsel.c	14 May 2003 18:13:26 -0000	1.33
+++ src/fsel.c	15 May 2003 21:08:33 -0000
@@ -431,33 +431,36 @@
    }
 
    if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) {
-      name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0));
+      int size = ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0);
+      name = malloc(size);
       if (!name)
 	 return -1;
 
+      ustrzcpy(name, size, s);
+      if (attrib & FA_DIREC)
+	 put_backslash(name);
+
+      /* Sort alphabetically with directories first. */
       for (c=0; c<flist->size; c++) {
 	 if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) {
 	    if (attrib & FA_DIREC)
-	       if (ustrfilecmp(s, flist->name[c]) < 0)
+	       if (ustrfilecmp(name, flist->name[c]) < 0)
 		  break;
 	 }
 	 else {
 	    if (attrib & FA_DIREC)
 	       break;
-	    if (ustrfilecmp(s, flist->name[c]) < 0)
+	    if (ustrfilecmp(name, flist->name[c]) < 0)
 	       break;
 	 }
       }
 
+      /* Shift in preparation for inserting the new entry. */
       for (c2=flist->size; c2>c; c2--)
 	 flist->name[c2] = flist->name[c2-1];
 
+      /* Insert the new entry. */
       flist->name[c] = name;
-      ustrcpy(flist->name[c], s);  /* ustrzcpy() not needed */
-
-      if (attrib & FA_DIREC)
-	 put_backslash(flist->name[c]);
-
       flist->size++;
    }
 
Index: src/unicode.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unicode.c,v
retrieving revision 1.23
diff -u -r1.23 unicode.c
--- src/unicode.c	1 Nov 2002 11:59:15 -0000	1.23
+++ src/unicode.c	15 May 2003 21:08:38 -0000
@@ -1723,12 +1723,15 @@
 char *_ustrdup(AL_CONST char *src, AL_METHOD(void *, malloc_func, (size_t)))
 {
    char *s;
+   int size;
    ASSERT(src);
    ASSERT(malloc_func);
 
-   s = malloc_func(ustrsizez(src));
+   size = ustrsizez(src);
+
+   s = malloc_func(size);
    if (s)
-      ustrcpy(s, src);  /* ustrzcpy() not needed */
+      ustrzcpy(s, size, src);
    else
       *allegro_errno = ENOMEM;
 
@@ -2206,7 +2209,7 @@
    skip_leading_delimiters:
 
    prev_str = s;
-   c = ugetxc((AL_CONST char **)&s);
+   c = ugetx(&s);
 
    setp = set;
 
@@ -2224,7 +2227,7 @@
 
    for (;;) {
       prev_str = s;
-      c = ugetxc((AL_CONST char **)&s);
+      c = ugetx(&s);
 
       setp = set;
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/