The following commit has been merged in the master branch:
commit b070e0ec0d33b585809dd420e0433a4f67ca12c0
Author: Guillem Jover <guil...@debian.org>
Date:   Wed Nov 3 09:41:29 2010 +0100

    libdpkg: Rewrite get_prefix_name() to be more efficient
    
    Avoid temporary allocations from the heap and use sprintf to write the
    string with delimited parts.

diff --git a/lib/dpkg/tarfn.c b/lib/dpkg/tarfn.c
index 564b4ee..fff39a5 100644
--- a/lib/dpkg/tarfn.c
+++ b/lib/dpkg/tarfn.c
@@ -95,26 +95,17 @@ StoC(const char *s, int size)
        return str;
 }
 
-/* FIXME: Rewrite using varbuf, once it supports the needed functionality. */
 static char *
 get_prefix_name(struct tar_header *h)
 {
-       char *prefix, *name, *s;
+       char *path;
 
-       /* The size is not going to be bigger than that. */
-       s = m_malloc(257);
+       path = m_malloc(sizeof(h->prefix) + 1 + sizeof(h->name) + 1);
 
-       prefix = StoC(h->prefix, sizeof(h->prefix));
-       name = StoC(h->name, sizeof(h->name));
+       sprintf(path, "%.*s/%.*s", (int)sizeof(h->prefix), h->prefix,
+               (int)sizeof(h->name), h->name);
 
-       strcpy(s, prefix);
-       strcat(s, "/");
-       strcat(s, name);
-
-       free(prefix);
-       free(name);
-
-       return s;
+       return path;
 }
 
 static mode_t

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to