Browse Source

Use m_asprintf() instead of nfmalloc() and string operations

This avoid the need to know the resulting string length beforehand, and
makes sure it's always going to get the right size. It also makes the
code way clearer.

Usage of nfmalloc() here was not appropriate anyway, as the variables
are only of temporary use, so switching to normal allocation gives
a side-effect “bug” fix.
Guillem Jover 15 years ago
parent
commit
76a6ebe12c
1 changed files with 6 additions and 5 deletions
  1. 6 5
      dpkg-split/queue.c

+ 6 - 5
dpkg-split/queue.c

@@ -174,11 +174,10 @@ void do_auto(const char *const *argv) {
     if (getc(part) != EOF) ohshit(_("part file `%.250s' has trailing garbage"),partfile);
     if (getc(part) != EOF) ohshit(_("part file `%.250s' has trailing garbage"),partfile);
     if (ferror(part)) rerr(partfile);
     if (ferror(part)) rerr(partfile);
     fclose(part);
     fclose(part);
-    p = nfmalloc(strlen(opt_depotdir) + 50);
-    q = nfmalloc(strlen(opt_depotdir) + 200);
-    sprintf(p, "%st.%lx", opt_depotdir, (long)getpid());
-    sprintf(q, "%s%s.%lx.%x.%x", opt_depotdir, refi->md5sum,
-            refi->maxpartlen,refi->thispartn,refi->maxpartn);
+
+    m_asprintf(&p, "%st.%lx", opt_depotdir, (long)getpid());
+    m_asprintf(&q, "%s%s.%lx.%x.%x", opt_depotdir, refi->md5sum,
+               refi->maxpartlen, refi->thispartn, refi->maxpartn);
     part= fopen(p,"w");
     part= fopen(p,"w");
     if (!part) ohshite(_("unable to open new depot file `%.250s'"),p);
     if (!part) ohshite(_("unable to open new depot file `%.250s'"),p);
     nr= fwrite(buffer,1,refi->filesize,part);
     nr= fwrite(buffer,1,refi->filesize,part);
@@ -189,6 +188,8 @@ void do_auto(const char *const *argv) {
       ohshite(_("unable to sync file '%s'"), p);
       ohshite(_("unable to sync file '%s'"), p);
     if (fclose(part)) werr(p);
     if (fclose(part)) werr(p);
     if (rename(p,q)) ohshite(_("unable to rename new depot file `%.250s' to `%.250s'"),p,q);
     if (rename(p,q)) ohshite(_("unable to rename new depot file `%.250s' to `%.250s'"),p,q);
+    free(q);
+    free(p);
 
 
     printf(_("Part %d of package %s filed (still want "),refi->thispartn,refi->package);
     printf(_("Part %d of package %s filed (still want "),refi->thispartn,refi->package);
     /* There are still some parts missing. */
     /* There are still some parts missing. */