diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-10-28 23:32:12 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-10-28 23:32:12 +0000 |
commit | 1c834407e39197d9d3f127d4783b75af5e793319 (patch) | |
tree | d9f20d07ff6021edefac50b83ed8719a00031143 /archival | |
parent | debb21ece7be5a17b468bab0cba74f8026008d0d (diff) | |
download | busybox-w32-1c834407e39197d9d3f127d4783b75af5e793319.tar.gz busybox-w32-1c834407e39197d9d3f127d4783b75af5e793319.tar.bz2 busybox-w32-1c834407e39197d9d3f127d4783b75af5e793319.zip |
Add some error messages, use xmalloc instead of malloc
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index f00c43913..83232fbe8 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c | |||
@@ -47,6 +47,8 @@ | |||
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | #include <limits.h> | 48 | #include <limits.h> |
49 | 49 | ||
50 | #include "libbb.h" | ||
51 | |||
50 | /* Constants for huffman coding */ | 52 | /* Constants for huffman coding */ |
51 | #define MAX_GROUPS 6 | 53 | #define MAX_GROUPS 6 |
52 | #define GROUP_SIZE 50 /* 64 would have been more efficient */ | 54 | #define GROUP_SIZE 50 /* 64 would have been more efficient */ |
@@ -520,7 +522,7 @@ extern int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len) | |||
520 | i=sizeof(bunzip_data); | 522 | i=sizeof(bunzip_data); |
521 | if(in_fd!=-1) i+=IOBUF_SIZE; | 523 | if(in_fd!=-1) i+=IOBUF_SIZE; |
522 | /* Allocate bunzip_data. Most fields initialize to zero. */ | 524 | /* Allocate bunzip_data. Most fields initialize to zero. */ |
523 | if(!(bd=*bdp=malloc(i))) return RETVAL_OUT_OF_MEMORY; | 525 | bd=*bdp=xmalloc(i); |
524 | memset(bd,0,sizeof(bunzip_data)); | 526 | memset(bd,0,sizeof(bunzip_data)); |
525 | /* Setup input buffer */ | 527 | /* Setup input buffer */ |
526 | if(-1==(bd->in_fd=in_fd)) { | 528 | if(-1==(bd->in_fd=in_fd)) { |
@@ -546,8 +548,7 @@ extern int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len) | |||
546 | uncompressed data. Allocate intermediate buffer for block. */ | 548 | uncompressed data. Allocate intermediate buffer for block. */ |
547 | bd->dbufSize=100000*(i-BZh0); | 549 | bd->dbufSize=100000*(i-BZh0); |
548 | 550 | ||
549 | if(!(bd->dbuf=malloc(bd->dbufSize * sizeof(int)))) | 551 | bd->dbuf=xmalloc(bd->dbufSize * sizeof(int)); |
550 | return RETVAL_OUT_OF_MEMORY; | ||
551 | return RETVAL_OK; | 552 | return RETVAL_OK; |
552 | } | 553 | } |
553 | 554 | ||
@@ -559,7 +560,7 @@ extern int uncompressStream(int src_fd, int dst_fd) | |||
559 | bunzip_data *bd; | 560 | bunzip_data *bd; |
560 | int i; | 561 | int i; |
561 | 562 | ||
562 | if(!(outbuf=malloc(IOBUF_SIZE))) return RETVAL_OUT_OF_MEMORY; | 563 | outbuf=xmalloc(IOBUF_SIZE); |
563 | if(!(i=start_bunzip(&bd,src_fd,0,0))) { | 564 | if(!(i=start_bunzip(&bd,src_fd,0,0))) { |
564 | for(;;) { | 565 | for(;;) { |
565 | if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; | 566 | if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; |
@@ -570,10 +571,22 @@ extern int uncompressStream(int src_fd, int dst_fd) | |||
570 | } | 571 | } |
571 | } | 572 | } |
572 | /* Check CRC and release memory */ | 573 | /* Check CRC and release memory */ |
573 | if(i==RETVAL_LAST_BLOCK && bd->headerCRC==bd->totalCRC) i=RETVAL_OK; | 574 | if(i==RETVAL_LAST_BLOCK) { |
575 | if (bd->headerCRC!=bd->totalCRC) { | ||
576 | bb_error_msg("Data integrity error when decompressing."); | ||
577 | } else { | ||
578 | i=RETVAL_OK; | ||
579 | } | ||
580 | } | ||
581 | else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { | ||
582 | bb_error_msg("Compressed file ends unexpectedly"); | ||
583 | } else { | ||
584 | bb_error_msg("Decompression failed"); | ||
585 | } | ||
574 | if(bd->dbuf) free(bd->dbuf); | 586 | if(bd->dbuf) free(bd->dbuf); |
575 | free(bd); | 587 | free(bd); |
576 | free(outbuf); | 588 | free(outbuf); |
589 | |||
577 | return i; | 590 | return i; |
578 | } | 591 | } |
579 | 592 | ||