lz4hc.c: clamp compression levels > 12
authorAlexey Tourbin <alexey.tourbin@gmail.com>
Sat, 29 Apr 2017 12:52:51 +0000 (15:52 +0300)
committerAlexey Tourbin <alexey.tourbin@gmail.com>
Sat, 29 Apr 2017 13:33:15 +0000 (16:33 +0300)
I noticed that, while 'lz4 -12' works fine, 'lz4 -13' does not compress
at all.

$ cat </etc/passwd |wc -c
2565
$ lz4 -12 </etc/passwd |wc -c
1456
$ lz4 -13 </etc/passwd |wc -c
2584

Perhaps the best way to fix this is to clamp the compression level
in the LZ4HC_compress_generic routine.

lib/lz4hc.c

index ac15d20..16fe029 100644 (file)
@@ -555,6 +555,8 @@ static int LZ4HC_compress_generic (
                 ctx->searchNum = LZ4HC_getSearchNum(cLevel);
                 return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, 128, 0);
             default:
+                cLevel = 12;
+                /* pass-through */
             case 12:
                 ctx->searchNum = LZ4HC_getSearchNum(cLevel);
                 return LZ4HC_compress_optimal(ctx, src, dst, *srcSizePtr, dstCapacity, limit, LZ4_OPT_NUM, 1);