summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Fankhauser hiddenalpha.ch2023-01-31 03:13:03 +0100
committerAndreas Fankhauser hiddenalpha.ch2023-01-31 03:14:19 +0100
commit8cf606b6a5567df81b9b9ece92a0fffaafb71849 (patch)
tree39d23b4a88f302bd29ea6bf7ff2757f695a9d4e9 /src
parent88358e97d7645004e6481353562450ffafd53072 (diff)
downloadDeflateAndInflate-8cf606b6a5567df81b9b9ece92a0fffaafb71849.zip
DeflateAndInflate-8cf606b6a5567df81b9b9ece92a0fffaafb71849.tar.gz
Try to move some older patches over from old sources
Diffstat (limited to 'src')
-rw-r--r--src/main/c/inflate.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/main/c/inflate.c b/src/main/c/inflate.c
index 2f1f991..0cdca87 100644
--- a/src/main/c/inflate.c
+++ b/src/main/c/inflate.c
@@ -62,10 +62,10 @@ static int doInflate( MyInflate*myInflate ){
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int err;
z_stream strm;
- uchar innBuf[65536];
+ uchar innBuf[65536]; /* TODO make at least 256k */
const int innBuf_cap = sizeof innBuf;
int innBuf_len = 0, innBuf_off = 0;
- uchar outBuf[65536];
+ uchar outBuf[65536]; /* TODO make at least 256k */
const int outBuf_cap = sizeof outBuf;
int outBuf_len = 0;
int inputIsEOF = 0;
@@ -88,7 +88,7 @@ static int doInflate( MyInflate*myInflate ){
return -1;
}
- for(; !inputIsEOF || !outputIsEOF ;){
+ for(; !outputIsEOF ;){
/* input */ {
int space = innBuf_cap - innBuf_len;
@@ -113,7 +113,7 @@ static int doInflate( MyInflate*myInflate ){
if( feof(stdin) ){
inputIsEOF = !0;
}else{
- fprintf(stderr, "Error: fread(): %s\n", strerror(errno));
+ fprintf(stderr, "inflate: fread(): %s\n", strerror(errno));
return -1;
}
}
@@ -156,37 +156,42 @@ static int doInflate( MyInflate*myInflate ){
outputIsEOF = !0;
}else if( err == Z_BUF_ERROR ){
/* Could not make any progress. Have to call again with updated buffers */
+#ifndef NDEBUG
+ fprintf(stderr, "inflate() -> Z_BUF_ERROR\n");
+ assert((strm.next_out - outBuf) > 0);
+#endif
noProgressSince += 1;
- if( noProgressSince > 42 ){
- fprintf(stderr, "Warn: inflate() -> Z_BUF_ERROR: %s (maybe EOF came too early?)\n",
- (strm.msg == NULL) ? "Could not make any progress" : strm.msg);
- return -1;
+ if( noProgressSince % 42000000 == 0 ){
+ fprintf(stderr, "inflate: Z_BUF_ERROR: %s",
+ (strm.msg != NULL) ? strm.msg : "Input data looks invalid");
}
}else if( strm.msg != NULL || errno ){
- fprintf(stderr, "Error: inflate(): %s\n", (strm.msg != NULL) ? strm.msg :
- strerror(errno));
+ fprintf(stderr, "inflate: Error: %s\n",
+ (strm.msg != NULL) ? strm.msg : strerror(errno));
return -1;
}else{
- fprintf(stderr, "Error: inflate(): -> %d\n", err);
+ fprintf(stderr, "inflate(): %d\n", err);
return -1;
}
- }else{
- noProgressSince = 0; /* reset as we just made progress */
}
innBuf_off += strm.next_in - innBuf;
outBuf_len = strm.next_out - outBuf;
- if( innBuf_off > innBuf_len ){ innBuf_off = innBuf_len; }
+ if( innBuf_off > innBuf_len ){
+ innBuf_off = innBuf_len; }
}
/* output */ {
err = fwrite(outBuf, 1, outBuf_len, stdout);
if(unlikely( err != outBuf_len )){
- fprintf(stderr, "Errro: fwrite(): %s\n", strerror(errno));
+ fprintf(stderr, "inflate: fwrite(): %s\n", strerror(errno));
return -1;
}
outBuf_len = 0;
}
}
+ if( !inputIsEOF ){
+ fprintf(stderr, "Warn: inflate complete, but input not EOF yet.\n");
+ }
err = inflateEnd(&strm);
if( err != Z_OK ){