浏览代码

libgis: add sanity check for compression_level

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61421 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 年之前
父节点
当前提交
8874a0dc31
共有 1 个文件被更改,包括 7 次插入4 次删除
  1. 7 4
      lib/gis/flate.c

+ 7 - 4
lib/gis/flate.c

@@ -328,10 +328,13 @@ G_zlib_compress(const unsigned char *src, int src_sz, unsigned char *dst,
     c_stream.avail_out = buf_sz;
     c_stream.next_out = buf;
 
-    /* Initialize using default compression (usually 6) */
-    err = deflateInit(&c_stream, G__.compression_level < 0
-		      ? Z_DEFAULT_COMPRESSION
-		      : G__.compression_level);
+    /* Initialize */
+    /* Valid zlib compression levels -1 - 9 */
+    /* zlib default: Z_DEFAULT_COMPRESSION = -1, equivalent to 6 
+     * as used here, 1 gives the best compromise between speed and compression */
+    err = deflateInit(&c_stream,
+                      (G__.compression_level < -1 || G__.compression_level > 9) 
+		      ? 1 : G__.compression_level);
 
     /* If there was an error initializing, return -1 */
     if (err != Z_OK) {