CLI : Added : capability to compress/decompress to NULL (useful for testings)
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Sun, 25 Sep 2011 20:11:05 +0000 (20:11 +0000)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Sun, 25 Sep 2011 20:11:05 +0000 (20:11 +0000)
Corrected small bug into LZ4_uncompress(). Update is recommended.

git-svn-id: https://lz4.googlecode.com/svn/trunk@28 650e7d94-2a16-8b24-b05c-7c0b3f6821cd

lz4.c
main.c

diff --git a/lz4.c b/lz4.c
index 8e9738c..fec366a 100644 (file)
--- a/lz4.c
+++ b/lz4.c
@@ -72,8 +72,8 @@
 #define COPYTOKEN 4\r
 #define COPYLENGTH 8\r
 #define LASTLITERALS 5\r
-#define MFLIMIT 12\r
-#define MINLENGTH 13\r
+#define MFLIMIT (COPYLENGTH+MINMATCH)\r
+#define MINLENGTH (MFLIMIT+1)\r
 \r
 #define MAXD_LOG 16\r
 #define MAX_DISTANCE ((1 << MAXD_LOG) - 1)\r
@@ -302,6 +302,7 @@ int LZ4_uncompress(char* source,
                { \r
                        if (ref > oend) goto _output_error;\r
                        memcpy(op, ip, length);\r
+                       ip+=length;\r
                        break;    // Necessarily EOF\r
                }\r
                LZ4_WILDCOPY(ip, op, ref);\r
diff --git a/main.c b/main.c
index f41330c..b6abfca 100644 (file)
--- a/main.c
+++ b/main.c
@@ -89,8 +89,8 @@ int usage()
        fprintf(stderr, " -c : force compression (default)\n");\r
        fprintf(stderr, " -d : force decompression \n");\r
        fprintf(stderr, " -h : help (this text)\n");    \r
-       fprintf(stderr, "input  : can be 'stdin' (pipe)  or a filename\n");\r
-       fprintf(stderr, "output : can be 'stdout' (pipe) or a filename\n");\r
+       fprintf(stderr, "input  : can be 'stdin' (pipe) or a filename\n");\r
+       fprintf(stderr, "output : can be 'stdout'(pipe) or a filename or 'nul'\n");\r
        return 0;\r
 }\r
 \r
@@ -113,11 +113,12 @@ int compress_file(char* input_filename, char* output_filename)
        FILE* foutput;\r
        char stdinmark[] = "stdin";\r
        char stdoutmark[] = "stdout";\r
+       char nulmark[] = "nul";\r
 \r
        if (!strcmp (input_filename, stdinmark)) {\r
                fprintf(stderr, "Using stdin for input\n");\r
                finput = stdin;\r
-#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */\r
+#ifdef _WIN32 // Need to set stdin/stdout to binary mode specifically for windows\r
                _setmode( _fileno( stdin ), _O_BINARY );\r
 #endif\r
        } else {\r
@@ -127,9 +128,12 @@ int compress_file(char* input_filename, char* output_filename)
        if (!strcmp (output_filename, stdoutmark)) {\r
                fprintf(stderr, "Using stdout for output\n");\r
                foutput = stdout;\r
-#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */\r
+#ifdef _WIN32 // Need to set stdin/stdout to binary mode specifically for windows\r
                _setmode( _fileno( stdout ), _O_BINARY );\r
 #endif\r
+       } else if (!strcmp (input_filename, nulmark)) {\r
+               fprintf(stderr, "Sending output to nul\n");\r
+               foutput = NULL;\r
        } else {\r
                foutput = fopen( output_filename, "wb" );\r
        }\r
@@ -186,6 +190,7 @@ int decode_file(char* input_filename, char* output_filename)
        FILE* foutput;\r
        char stdinmark[] = "stdin";\r
        char stdoutmark[] = "stdout";\r
+       char nulmark[] = "nul";\r
 \r
        if (!strcmp (input_filename, stdinmark)) {\r
                fprintf(stderr, "Using stdin for input\n");\r
@@ -203,6 +208,9 @@ int decode_file(char* input_filename, char* output_filename)
 #ifdef _WIN32 // need to set stdin/stdout to binary mode\r
                _setmode( _fileno( stdout ), _O_BINARY );\r
 #endif\r
+       } else if (!strcmp (input_filename, nulmark)) {\r
+               fprintf(stderr, "Sending output to nul\n");\r
+               foutput = NULL;\r
        } else {\r
                foutput = fopen( output_filename, "wb" );\r
        }\r