From c59e0b5643fcba7b95a0e47b3db9258af83d8603 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 19 Oct 2019 13:04:58 +0000
Subject: [PATCH] Decompression seem to work

---
 src/b64zlib_compression.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/b64zlib_compression.c b/src/b64zlib_compression.c
index 09ed942..99c1921 100644
--- a/src/b64zlib_compression.c
+++ b/src/b64zlib_compression.c
@@ -91,7 +91,6 @@
 	//test decoding and decompression
 	char *test_data = ts_decompress((unsigned char *)return_value, nbase1+nbase2, data_len);
 	free(test_data);
-	fprintf(stderr,"WAS HERE!\n");
 	return return_value;
 }
 
@@ -103,8 +102,10 @@
 	if(header==NULL) fprintf(stderr, "Error decoding header\n");
 	fprintf(stderr,"Header=%d, %d, %d, %d\n", header[0],header[1], header[2], header[3]);
 	unsigned char *decoded_data=base64_decode((const char *)&compressed_data[encoded_header_len], data_len-encoded_header_len, &nbase1);
+	if(decoded_data==NULL) fprintf(stderr, "Error decoding compressed data\n");
 	unsigned char *return_value=(unsigned char *)malloc(result_len*sizeof(char));
 	uncompress(return_value, (unsigned long *)&result_len, decoded_data, header[3]);
+//	fprintf(stderr,"RESULT_LEN=%d\n",result_len);
 	free(decoded_data);
 	free(header);
 	return (char *)return_value;
@@ -123,7 +124,6 @@
                                 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                                 'w', 'x', 'y', 'z', '0', '1', '2', '3',
                                 '4', '5', '6', '7', '8', '9', '+', '/'};
-static char *decoding_table = NULL;
 static int mod_table[] = {0, 2, 1};
 
 
@@ -155,7 +155,7 @@
 
 unsigned char *base64_decode(const char *data, size_t input_length, size_t *output_length) {
 	int i,j;
-	if (decoding_table == NULL) build_decoding_table();
+	char *decoding_table = build_decoding_table();
 
 	if (input_length % 4 != 0) return NULL;
 
@@ -181,23 +181,20 @@
        	if (j < *output_length) decoded_data[j++] = (triple >> 1 * 8) & 0xFF;
        	if (j < *output_length) decoded_data[j++] = (triple >> 0 * 8) & 0xFF;
     }
-	if(decoding_table !=NULL) free(decoding_table);
+	free(decoding_table);
     return decoded_data;
 }
 
 
-void build_decoding_table() {
-
-    decoding_table = malloc(256);
+char *build_decoding_table() {
+    char *decoding_table = malloc(256);
 	int i;
     for (i = 0; i < 64; i++)
 		decoding_table[(unsigned char) encoding_table[i]] = i;
+	return decoding_table;
 }
 
 
-void base64_cleanup() {
-    free(decoding_table);
-}
 
 
 

--
Gitblit v1.9.3