[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 01/15] libdpkg: Reduce scope of combuf[] in compress_cat



Move it closer to its actual usage.  This should make it easier to
factor out repeated code and saves some stack space in cases where
there is no command line argument to compute.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 lib/dpkg/compression.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/dpkg/compression.c b/lib/dpkg/compression.c
index 2fa0476..f7444af 100644
--- a/lib/dpkg/compression.c
+++ b/lib/dpkg/compression.c
@@ -104,7 +104,6 @@ void decompress_cat(enum compress_type type, int fd_in, int fd_out, char *desc,
 void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *compression, char *desc, ...) {
   va_list al;
   struct varbuf v = VARBUF_INIT;
-  char combuf[6];
 
   va_start(al,desc);
   varbufvprintf(&v, desc, al);
@@ -118,6 +117,7 @@ void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *co
     case compress_type_gzip:
 #ifdef WITH_ZLIB
       {
+        char combuf[6];
         int actualread, actualwrite;
         char buffer[4096];
         gzFile gzfile;
@@ -146,13 +146,17 @@ void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *co
         exit(0);
       }
 #else
-      strncpy(combuf, "-9c", sizeof(combuf));
-      combuf[1]= *compression;
-      fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf);
+      {
+        char combuf[6];
+        strncpy(combuf, "-9c", sizeof(combuf));
+        combuf[1]= *compression;
+        fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf);
+      }
 #endif
     case compress_type_bzip2:
 #ifdef WITH_BZ2
       {
+        char combuf[6];
         int actualread, actualwrite;
         char buffer[4096];
         BZFILE *bzfile;
@@ -181,14 +185,20 @@ void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *co
         exit(0);
       }
 #else
-      strncpy(combuf, "-9c", sizeof(combuf));
-      combuf[1]= *compression;
-      fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf);
+      {
+        char combuf[6];
+        strncpy(combuf, "-9c", sizeof(combuf));
+        combuf[1]= *compression;
+        fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf);
+      }
 #endif
     case compress_type_lzma:
-      strncpy(combuf, "-9c", sizeof(combuf));
-      combuf[1] = *compression;
-      fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, v.buf);
+      {
+        char combuf[6];
+        strncpy(combuf, "-9c", sizeof(combuf));
+        combuf[1] = *compression;
+        fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, v.buf);
+      }
     case compress_type_cat:
       fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf);
       exit(0);
-- 
1.6.5.rc1.199.g596ec


Reply to: