lib/decompress_bunzip2.c: fix checkstack warning
[deliverable/linux.git] / lib / decompress_bunzip2.c
index 76074209f9a2eecdc0cdab8278916aa3de1fcdf2..81c8bb1cc6aae1dc58527f7cf509c9608b6af436 100644 (file)
@@ -107,6 +107,8 @@ struct bunzip_data {
        unsigned char selectors[32768];         /* nSelectors = 15 bits */
        struct group_data groups[MAX_GROUPS];   /* Huffman coding tables */
        int io_error;                   /* non-zero if we have IO error */
+       int byteCount[256];
+       unsigned char symToByte[256], mtfSymbol[256];
 };
 
 
@@ -158,14 +160,16 @@ static int INIT get_next_block(struct bunzip_data *bd)
        int *base = NULL;
        int *limit = NULL;
        int dbufCount, nextSym, dbufSize, groupCount, selector,
-               i, j, k, t, runPos, symCount, symTotal, nSelectors,
-               byteCount[256];
-       unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
+               i, j, k, t, runPos, symCount, symTotal, nSelectors, *byteCount;
+       unsigned char uc, *symToByte, *mtfSymbol, *selectors;
        unsigned int *dbuf, origPtr;
 
        dbuf = bd->dbuf;
        dbufSize = bd->dbufSize;
        selectors = bd->selectors;
+       byteCount = bd->byteCount;
+       symToByte = bd->symToByte;
+       mtfSymbol = bd->mtfSymbol;
 
        /* Read in header signature and CRC, then validate signature.
           (last block signature means CRC is for whole file, return now) */
@@ -637,6 +641,8 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
 
        /* Allocate bunzip_data.  Most fields initialize to zero. */
        bd = *bdp = malloc(i);
+       if (!bd)
+               return RETVAL_OUT_OF_MEMORY;
        memset(bd, 0, sizeof(struct bunzip_data));
        /* Setup input buffer */
        bd->inbuf = inbuf;
@@ -664,6 +670,8 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
        bd->dbufSize = 100000*(i-BZh0);
 
        bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
+       if (!bd->dbuf)
+               return RETVAL_OUT_OF_MEMORY;
        return RETVAL_OK;
 }
 
@@ -686,7 +694,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
 
        if (!outbuf) {
                error("Could not allocate output bufer");
-               return -1;
+               return RETVAL_OUT_OF_MEMORY;
        }
        if (buf)
                inbuf = buf;
@@ -694,6 +702,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
                inbuf = malloc(BZIP2_IOBUF_SIZE);
        if (!inbuf) {
                error("Could not allocate input bufer");
+               i = RETVAL_OUT_OF_MEMORY;
                goto exit_0;
        }
        i = start_bunzip(&bd, inbuf, len, fill);
@@ -720,11 +729,14 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
        } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
                error("Compressed file ends unexpectedly");
        }
+       if (!bd)
+               goto exit_1;
        if (bd->dbuf)
                large_free(bd->dbuf);
        if (pos)
                *pos = bd->inbufPos;
        free(bd);
+exit_1:
        if (!buf)
                free(inbuf);
 exit_0:
This page took 0.025532 seconds and 5 git commands to generate.