2003-06-06 18:18:12

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib cleanup #1 local

Hi Linus!

Simple s/local/static/.

J?rn

--
The cost of changing business rules is much more expensive for software
than for a secretaty.
-- unknown

--- linux-2.5.70-bk11/lib/zlib_deflate/deftree.c~zlib_cleanup_local 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deftree.c 2003-06-06 19:45:24.000000000 +0200
@@ -60,16 +60,16 @@
#define REPZ_11_138 18
/* repeat a zero length 11-138 times (7 bits of repeat count) */

-local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
+static const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};

-local const int extra_dbits[D_CODES] /* extra bits for each distance code */
+static const int extra_dbits[D_CODES] /* extra bits for each distance code */
= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};

-local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
+static const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};

-local const uch bl_order[BL_CODES]
+static const uch bl_order[BL_CODES]
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
/* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes.
@@ -84,31 +84,31 @@
* Local data. These are initialized only once.
*/

-local ct_data static_ltree[L_CODES+2];
+static ct_data static_ltree[L_CODES+2];
/* The static literal tree. Since the bit lengths are imposed, there is no
* need for the L_CODES extra codes used during heap construction. However
* The codes 286 and 287 are needed to build a canonical tree (see zlib_tr_init
* below).
*/

-local ct_data static_dtree[D_CODES];
+static ct_data static_dtree[D_CODES];
/* The static distance tree. (Actually a trivial tree since all codes use
* 5 bits.)
*/

-local uch dist_code[512];
+static uch dist_code[512];
/* distance codes. The first 256 values correspond to the distances
* 3 .. 258, the last 256 values correspond to the top 8 bits of
* the 15 bit distances.
*/

-local uch length_code[MAX_MATCH-MIN_MATCH+1];
+static uch length_code[MAX_MATCH-MIN_MATCH+1];
/* length code for each normalized match length (0 == MIN_MATCH) */

-local int base_length[LENGTH_CODES];
+static int base_length[LENGTH_CODES];
/* First normalized length for each code (0 = MIN_MATCH) */

-local int base_dist[D_CODES];
+static int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */

struct static_tree_desc_s {
@@ -119,37 +119,37 @@
int max_length; /* max bit length for the codes */
};

-local static_tree_desc static_l_desc =
+static static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};

-local static_tree_desc static_d_desc =
+static static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};

-local static_tree_desc static_bl_desc =
+static static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};

/* ===========================================================================
* Local (static) routines in this file.
*/

-local void tr_static_init (void);
-local void init_block (deflate_state *s);
-local void pqdownheap (deflate_state *s, ct_data *tree, int k);
-local void gen_bitlen (deflate_state *s, tree_desc *desc);
-local void gen_codes (ct_data *tree, int max_code, ush *bl_count);
-local void build_tree (deflate_state *s, tree_desc *desc);
-local void scan_tree (deflate_state *s, ct_data *tree, int max_code);
-local void send_tree (deflate_state *s, ct_data *tree, int max_code);
-local int build_bl_tree (deflate_state *s);
-local void send_all_trees (deflate_state *s, int lcodes, int dcodes,
+static void tr_static_init (void);
+static void init_block (deflate_state *s);
+static void pqdownheap (deflate_state *s, ct_data *tree, int k);
+static void gen_bitlen (deflate_state *s, tree_desc *desc);
+static void gen_codes (ct_data *tree, int max_code, ush *bl_count);
+static void build_tree (deflate_state *s, tree_desc *desc);
+static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
+static void send_tree (deflate_state *s, ct_data *tree, int max_code);
+static int build_bl_tree (deflate_state *s);
+static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
int blcodes);
-local void compress_block (deflate_state *s, ct_data *ltree,
+static void compress_block (deflate_state *s, ct_data *ltree,
ct_data *dtree);
-local void set_data_type (deflate_state *s);
-local unsigned bi_reverse (unsigned value, int length);
-local void bi_windup (deflate_state *s);
-local void bi_flush (deflate_state *s);
-local void copy_block (deflate_state *s, char *buf, unsigned len,
+static void set_data_type (deflate_state *s);
+static unsigned bi_reverse (unsigned value, int length);
+static void bi_windup (deflate_state *s);
+static void bi_flush (deflate_state *s);
+static void copy_block (deflate_state *s, char *buf, unsigned len,
int header);

#ifndef DEBUG_ZLIB
@@ -174,9 +174,9 @@
* IN assertion: length <= 16 and value fits in length bits.
*/
#ifdef DEBUG_ZLIB
-local void send_bits (deflate_state *s, int value, int length);
+static void send_bits (deflate_state *s, int value, int length);

-local void send_bits(
+static void send_bits(
deflate_state *s,
int value, /* value to send */
int length /* number of bits */
@@ -226,7 +226,7 @@
* this function may be called by two threads concurrently, but this is
* harmless since both invocations do exactly the same thing.
*/
-local void tr_static_init()
+static void tr_static_init()
{
static int static_init_done = 0;
int n; /* iterates over tree elements */
@@ -326,7 +326,7 @@
/* ===========================================================================
* Initialize a new block.
*/
-local void init_block(s)
+static void init_block(s)
deflate_state *s;
{
int n; /* iterates over tree elements */
@@ -370,7 +370,7 @@
* when the heap property is re-established (each father smaller than its
* two sons).
*/
-local void pqdownheap(
+static void pqdownheap(
deflate_state *s,
ct_data *tree, /* the tree to restore */
int k /* node to move down */
@@ -406,7 +406,7 @@
* The length opt_len is updated; static_len is also updated if stree is
* not null.
*/
-local void gen_bitlen(
+static void gen_bitlen(
deflate_state *s,
tree_desc *desc /* the tree descriptor */
)
@@ -494,7 +494,7 @@
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
-local void gen_codes(
+static void gen_codes(
ct_data *tree, /* the tree to decorate */
int max_code, /* largest code with non zero frequency */
ush *bl_count /* number of codes at each bit length */
@@ -537,7 +537,7 @@
* and corresponding code. The length opt_len is updated; static_len is
* also updated if stree is not null. The field max_code is set.
*/
-local void build_tree(
+static void build_tree(
deflate_state *s,
tree_desc *desc /* the tree descriptor */
)
@@ -625,7 +625,7 @@
* Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree.
*/
-local void scan_tree(
+static void scan_tree(
deflate_state *s,
ct_data *tree, /* the tree to be scanned */
int max_code /* and its largest code of non zero frequency */
@@ -671,7 +671,7 @@
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
*/
-local void send_tree(
+static void send_tree(
deflate_state *s,
ct_data *tree, /* the tree to be scanned */
int max_code /* and its largest code of non zero frequency */
@@ -723,7 +723,7 @@
* Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send.
*/
-local int build_bl_tree(
+static int build_bl_tree(
deflate_state *s
)
{
@@ -759,7 +759,7 @@
* lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/
-local void send_all_trees(
+static void send_all_trees(
deflate_state *s,
int lcodes, /* number of codes for each tree */
int dcodes, /* number of codes for each tree */
@@ -1017,7 +1017,7 @@
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
-local void compress_block(
+static void compress_block(
deflate_state *s,
ct_data *ltree, /* literal tree */
ct_data *dtree /* distance tree */
@@ -1071,7 +1071,7 @@
* IN assertion: the fields freq of dyn_ltree are set and the total of all
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
*/
-local void set_data_type(
+static void set_data_type(
deflate_state *s
)
{
@@ -1088,7 +1088,7 @@
* Copy a stored block, storing first the length and its
* one's complement if requested.
*/
-local void copy_block(
+static void copy_block(
deflate_state *s,
char *buf, /* the input data */
unsigned len, /* its length */
--- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_cleanup_local 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 19:46:09.000000000 +0200
@@ -66,18 +66,18 @@
typedef block_state (*compress_func) (deflate_state *s, int flush);
/* Compression function. Returns the block state after the call. */

-local void fill_window (deflate_state *s);
-local block_state deflate_stored (deflate_state *s, int flush);
-local block_state deflate_fast (deflate_state *s, int flush);
-local block_state deflate_slow (deflate_state *s, int flush);
-local void lm_init (deflate_state *s);
-local void putShortMSB (deflate_state *s, uInt b);
-local void flush_pending (z_streamp strm);
-local int read_buf (z_streamp strm, Byte *buf, unsigned size);
-local uInt longest_match (deflate_state *s, IPos cur_match);
+static void fill_window (deflate_state *s);
+static block_state deflate_stored (deflate_state *s, int flush);
+static block_state deflate_fast (deflate_state *s, int flush);
+static block_state deflate_slow (deflate_state *s, int flush);
+static void lm_init (deflate_state *s);
+static void putShortMSB (deflate_state *s, uInt b);
+static void flush_pending (z_streamp strm);
+static int read_buf (z_streamp strm, Byte *buf, unsigned size);
+static uInt longest_match (deflate_state *s, IPos cur_match);

#ifdef DEBUG_ZLIB
-local void check_match (deflate_state *s, IPos start, IPos match,
+static void check_match (deflate_state *s, IPos start, IPos match,
int length);
#endif

@@ -111,7 +111,7 @@
compress_func func;
} config;

-local const config configuration_table[10] = {
+static const config configuration_table[10] = {
/* good lazy nice chain */
/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */
@@ -371,7 +371,7 @@
* IN assertion: the stream state is correct and there is enough room in
* pending_buf.
*/
-local void putShortMSB (s, b)
+static void putShortMSB (s, b)
deflate_state *s;
uInt b;
{
@@ -385,7 +385,7 @@
* to avoid allocating a large strm->next_out buffer and copying into it.
* (See also read_buf()).
*/
-local void flush_pending(strm)
+static void flush_pending(strm)
z_streamp strm;
{
deflate_state *s = (deflate_state *) strm->state;
@@ -630,7 +630,7 @@
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
-local int read_buf(
+static int read_buf(
z_streamp strm,
Byte *buf,
unsigned size
@@ -656,7 +656,7 @@
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
-local void lm_init (s)
+static void lm_init (s)
deflate_state *s;
{
s->window_size = (ulg)2L*s->w_size;
@@ -690,7 +690,7 @@
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent.
*/
-local uInt longest_match(s, cur_match)
+static uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
@@ -832,7 +832,7 @@
/* ===========================================================================
* Check that the match at match_start is indeed a match.
*/
-local void check_match(s, start, match, length)
+static void check_match(s, start, match, length)
deflate_state *s;
IPos start, match;
int length;
@@ -866,7 +866,7 @@
* performed for at least two bytes (required for the zip translate_eol
* option -- not supported here).
*/
-local void fill_window(s)
+static void fill_window(s)
deflate_state *s;
{
register unsigned n, m;
@@ -985,7 +985,7 @@
* NOTE: this function should be optimized to avoid extra copying from
* window to pending_buf.
*/
-local block_state deflate_stored(s, flush)
+static block_state deflate_stored(s, flush)
deflate_state *s;
int flush;
{
@@ -1043,7 +1043,7 @@
* new strings in the dictionary only for unmatched strings or for short
* matches. It is used only for the fast compression options.
*/
-local block_state deflate_fast(s, flush)
+static block_state deflate_fast(s, flush)
deflate_state *s;
int flush;
{
@@ -1136,7 +1136,7 @@
* evaluation for matches: a match is finally adopted only if there is
* no better match at the next window position.
*/
-local block_state deflate_slow(s, flush)
+static block_state deflate_slow(s, flush)
deflate_state *s;
int flush;
{
--- linux-2.5.70-bk11/lib/zlib_inflate/inffixed.h~zlib_cleanup_local 2003-04-07 19:30:46.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inffixed.h 2003-06-06 19:46:27.000000000 +0200
@@ -7,9 +7,9 @@
subject to change. Applications should only use zlib.h.
*/

-local uInt fixed_bl = 9;
-local uInt fixed_bd = 5;
-local inflate_huft fixed_tl[] = {
+static uInt fixed_bl = 9;
+static uInt fixed_bd = 5;
+static inflate_huft fixed_tl[] = {
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
@@ -139,7 +139,7 @@
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
};
-local inflate_huft fixed_td[] = {
+static inflate_huft fixed_td[] = {
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
{{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
--- linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c~zlib_cleanup_local 2003-06-06 15:56:16.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c 2003-06-06 19:46:59.000000000 +0200
@@ -22,7 +22,7 @@
#define bits word.what.Bits


-local int huft_build (
+static int huft_build (
uInt *, /* code lengths in bits */
uInt, /* number of codes */
uInt, /* number of "simple" codes */
@@ -35,18 +35,18 @@
uInt * ); /* space for values */

/* Tables for deflate from PKZIP's appnote.txt. */
-local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
+static const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
/* see note #13 above about 258 */
-local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
+static const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
-local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
+static const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
-local const uInt cpdext[30] = { /* Extra bits for distance codes */
+static const uInt cpdext[30] = { /* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
@@ -87,7 +87,7 @@
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15 /* maximum bit length of any code */

-local int huft_build(
+static int huft_build(
uInt *b, /* code lengths in bits (all assumed <= BMAX) */
uInt n, /* number of codes (assumed <= 288) */
uInt s, /* number of simple-valued codes (0..s-1) */
--- linux-2.5.70-bk11/lib/zlib_inflate/infblock.c~zlib_cleanup_local 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/infblock.c 2003-06-06 19:47:25.000000000 +0200
@@ -16,7 +16,7 @@
#define bits word.what.Bits

/* Table for deflate from PKZIP's appnote.txt. */
-local const uInt border[] = { /* Order of the bit length code lengths */
+static const uInt border[] = { /* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};

/*
--- linux-2.5.70-bk11/include/linux/zutil.h~zlib_cleanup_local 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/include/linux/zutil.h 2003-06-06 19:50:47.000000000 +0200
@@ -18,11 +18,6 @@
#include <linux/errno.h>
#include <linux/kernel.h>

-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;


2003-06-06 18:19:16

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib cleanup #2 cpp

Hope we don't use any cplusplus in the kernel.

J?rn

--
Those who come seeking peace without a treaty are plotting.
-- Sun Tzu

--- linux-2.5.70-bk11/include/linux/zlib.h~zlib_cleanup_cpp 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/include/linux/zlib.h 2003-06-06 19:53:06.000000000 +0200
@@ -33,10 +33,6 @@

#include <linux/zconf.h>

-#ifdef __cplusplus
-extern "C" {
-#endif
-
#define ZLIB_VERSION "1.1.3"

/*
@@ -640,8 +636,4 @@
extern int zlib_inflateSyncPoint (z_streamp z);
extern const uLong * zlib_get_crc_table (void);

-#ifdef __cplusplus
-}
-#endif
-
#endif /* _ZLIB_H */

2003-06-06 18:26:11

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib cleanup #3 Z_NULL

Hi Linus!

s/Z_NULL/NULL/g.

This still demands a follow-up patch as I didn't remove the pointless
casts. (inflate_huft *)NULL indeed.

How do you feel about "if (z->state->blocks != NULL)"? Remove the
pointless !=NULL or keep it?

J?rn

--
Public Domain - Free as in Beer
General Public - Free as in Speech
BSD License - Free as in Enterprise
Shared Source - Free as in "Work will make you..."

--- linux-2.5.70-bk11/lib/zlib_inflate/inflate.c~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inflate.c 2003-06-06 20:14:27.000000000 +0200
@@ -18,12 +18,12 @@
z_streamp z
)
{
- if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL)
+ if (z == NULL || z->state == NULL || z->workspace == NULL)
return Z_STREAM_ERROR;
z->total_in = z->total_out = 0;
- z->msg = Z_NULL;
+ z->msg = NULL;
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
- zlib_inflate_blocks_reset(z->state->blocks, z, Z_NULL);
+ zlib_inflate_blocks_reset(z->state->blocks, z, NULL);
return Z_OK;
}

@@ -32,11 +32,11 @@
z_streamp z
)
{
- if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL)
+ if (z == NULL || z->state == NULL || z->workspace == NULL)
return Z_STREAM_ERROR;
- if (z->state->blocks != Z_NULL)
+ if (z->state->blocks != NULL)
zlib_inflate_blocks_free(z->state->blocks, z);
- z->state = Z_NULL;
+ z->state = NULL;
return Z_OK;
}

@@ -48,16 +48,16 @@
int stream_size
)
{
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
- stream_size != sizeof(z_stream) || z->workspace == Z_NULL)
+ if (version == NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != sizeof(z_stream) || z->workspace == NULL)
return Z_VERSION_ERROR;

/* initialize state */
- if (z == Z_NULL)
+ if (z == NULL)
return Z_STREAM_ERROR;
- z->msg = Z_NULL;
+ z->msg = NULL;
z->state = &WS(z)->internal_state;
- z->state->blocks = Z_NULL;
+ z->state->blocks = NULL;

/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
@@ -77,8 +77,8 @@

/* create inflate_blocks state */
if ((z->state->blocks =
- zlib_inflate_blocks_new(z, z->state->nowrap ? Z_NULL : zlib_adler32, (uInt)1 << w))
- == Z_NULL)
+ zlib_inflate_blocks_new(z, z->state->nowrap ? NULL : zlib_adler32, (uInt)1 << w))
+ == NULL)
{
zlib_inflateEnd(z);
return Z_MEM_ERROR;
@@ -125,7 +125,7 @@
int r, trv;
uInt b;

- if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
+ if (z == NULL || z->state == NULL || z->next_in == NULL)
return Z_STREAM_ERROR;
trv = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
r = Z_BUF_ERROR;
@@ -260,7 +260,7 @@
uLong r, w; /* temporaries to save total_in and total_out */

/* set up */
- if (z == Z_NULL || z->state == Z_NULL)
+ if (z == NULL || z->state == NULL)
return Z_STREAM_ERROR;
if (z->state->mode != I_BAD)
{
@@ -313,7 +313,7 @@
z_streamp z
)
{
- if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
+ if (z == NULL || z->state == NULL || z->state->blocks == NULL)
return Z_STREAM_ERROR;
return zlib_inflate_blocks_sync_point(z->state->blocks);
}
@@ -352,7 +352,7 @@
/* is there room until end of buffer? */
if (t > m) t = m;
/* update check information */
- if (s->checkfn != Z_NULL)
+ if (s->checkfn != NULL)
s->check = (*s->checkfn)(s->check, q, t);
memcpy(q, p, t);
q += t;
--- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 20:14:27.000000000 +0200
@@ -199,13 +199,13 @@
* output size for (length,distance) codes is <= 24 bits.
*/

- if (version == Z_NULL || version[0] != my_version[0] ||
+ if (version == NULL || version[0] != my_version[0] ||
stream_size != sizeof(z_stream)) {
return Z_VERSION_ERROR;
}
- if (strm == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == NULL) return Z_STREAM_ERROR;

- strm->msg = Z_NULL;
+ strm->msg = NULL;

if (level == Z_DEFAULT_COMPRESSION) level = 6;

@@ -266,7 +266,7 @@
uInt n;
IPos hash_head = 0;

- if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
+ if (strm == NULL || strm->state == NULL || dictionary == NULL)
return Z_STREAM_ERROR;

s = (deflate_state *) strm->state;
@@ -305,11 +305,11 @@
{
deflate_state *s;

- if (strm == Z_NULL || strm->state == Z_NULL)
+ if (strm == NULL || strm->state == NULL)
return Z_STREAM_ERROR;

strm->total_in = strm->total_out = 0;
- strm->msg = Z_NULL;
+ strm->msg = NULL;
strm->data_type = Z_UNKNOWN;

s = (deflate_state *)strm->state;
@@ -340,7 +340,7 @@
compress_func func;
int err = Z_OK;

- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR;
s = (deflate_state *) strm->state;

if (level == Z_DEFAULT_COMPRESSION) {
@@ -394,7 +394,7 @@
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;

- if (strm->next_out != Z_NULL) {
+ if (strm->next_out != NULL) {
memcpy(strm->next_out, s->pending_out, len);
strm->next_out += len;
}
@@ -416,13 +416,13 @@
int old_flush; /* value of flush param for previous deflate call */
deflate_state *s;

- if (strm == Z_NULL || strm->state == Z_NULL ||
+ if (strm == NULL || strm->state == NULL ||
flush > Z_FINISH || flush < 0) {
return Z_STREAM_ERROR;
}
s = (deflate_state *) strm->state;

- if ((strm->next_in == Z_NULL && strm->avail_in != 0) ||
+ if ((strm->next_in == NULL && strm->avail_in != 0) ||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
return Z_STREAM_ERROR;
}
@@ -553,7 +553,7 @@
int status;
deflate_state *s;

- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR;
s = (deflate_state *) strm->state;

status = s->status;
@@ -562,7 +562,7 @@
return Z_STREAM_ERROR;
}

- strm->state = Z_NULL;
+ strm->state = NULL;

return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
}
@@ -584,7 +584,7 @@
deflate_workspace *mem;


- if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ if (source == NULL || dest == NULL || source->state == NULL) {
return Z_STREAM_ERROR;
}

@@ -962,7 +962,7 @@
#define FLUSH_BLOCK_ONLY(s, eof) { \
zlib_tr_flush_block(s, (s->block_start >= 0L ? \
(char *)&s->window[(unsigned)s->block_start] : \
- (char *)Z_NULL), \
+ (char *)NULL), \
(ulg)((long)s->strstart - s->block_start), \
(eof)); \
s->block_start = s->strstart; \
--- linux-2.5.70-bk11/lib/zlib_inflate/infblock.c~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/infblock.c 2003-06-06 20:14:27.000000000 +0200
@@ -71,7 +71,7 @@
uLong *c
)
{
- if (c != Z_NULL)
+ if (c != NULL)
*c = s->check;
if (s->mode == CODES)
zlib_inflate_codes_free(s->sub.decode.codes, z);
@@ -79,8 +79,8 @@
s->bitk = 0;
s->bitb = 0;
s->read = s->write = s->window;
- if (s->checkfn != Z_NULL)
- z->adler = s->check = (*s->checkfn)(0L, (const Byte *)Z_NULL, 0);
+ if (s->checkfn != NULL)
+ z->adler = s->check = (*s->checkfn)(0L, (const Byte *)NULL, 0);
}

inflate_blocks_statef *zlib_inflate_blocks_new(
@@ -97,7 +97,7 @@
s->end = s->window + w;
s->checkfn = c;
s->mode = TYPE;
- zlib_inflate_blocks_reset(s, z, Z_NULL);
+ zlib_inflate_blocks_reset(s, z, NULL);
return s;
}

@@ -141,7 +141,7 @@

zlib_inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = zlib_inflate_codes_new(bl, bd, tl, td, z);
- if (s->sub.decode.codes == Z_NULL)
+ if (s->sub.decode.codes == NULL)
{
r = Z_MEM_ERROR;
LEAVE
@@ -270,7 +270,7 @@
s->sub.trees.index = i;
}
}
- s->sub.trees.tb = Z_NULL;
+ s->sub.trees.tb = NULL;
{
uInt bl, bd;
inflate_huft *tl, *td;
@@ -289,7 +289,7 @@
r = t;
LEAVE
}
- if ((c = zlib_inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
+ if ((c = zlib_inflate_codes_new(bl, bd, tl, td, z)) == NULL)
{
r = Z_MEM_ERROR;
LEAVE
@@ -333,7 +333,7 @@
z_streamp z
)
{
- zlib_inflate_blocks_reset(s, z, Z_NULL);
+ zlib_inflate_blocks_reset(s, z, NULL);
return Z_OK;
}

@@ -351,7 +351,7 @@

/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
- * IN assertion: s != Z_NULL
+ * IN assertion: s != NULL
*/
int zlib_inflate_blocks_sync_point(
inflate_blocks_statef *s
--- linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c 2003-06-06 20:14:27.000000000 +0200
@@ -139,7 +139,7 @@
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
- *t = (inflate_huft *)Z_NULL;
+ *t = (inflate_huft *)NULL;
*m = 0;
return Z_OK;
}
@@ -193,8 +193,8 @@
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
- u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
- q = (inflate_huft *)Z_NULL; /* ditto */
+ u[0] = (inflate_huft *)NULL; /* just to keep compilers happy */
+ q = (inflate_huft *)NULL; /* ditto */
z = 0; /* ditto */

/* go through the bit lengths (k already is bits in shortest code) */
@@ -302,7 +302,7 @@
uInt *v; /* work area for huft_build */

v = WS(z)->tree_work_area_1;
- r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL,
+ r = huft_build(c, 19, 19, (uInt*)NULL, (uInt*)NULL,
tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
--- linux-2.5.70-bk11/lib/zlib_inflate/infutil.c~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/infutil.c 2003-06-06 20:14:27.000000000 +0200
@@ -44,7 +44,7 @@
z->total_out += n;

/* update check information */
- if (s->checkfn != Z_NULL)
+ if (s->checkfn != NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);

/* copy as far as end of window */
@@ -70,7 +70,7 @@
z->total_out += n;

/* update check information */
- if (s->checkfn != Z_NULL)
+ if (s->checkfn != NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);

/* copy */
--- linux-2.5.70-bk11/include/linux/zlib.h~zlib_cleanup_Z_NULL 2003-06-06 20:14:10.000000000 +0200
+++ linux-2.5.70-bk11/include/linux/zlib.h 2003-06-06 20:15:04.000000000 +0200
@@ -91,7 +91,7 @@
memory management. The compression library attaches no meaning to the
opaque value.

- zalloc must return Z_NULL if there is not enough memory for the object.
+ zalloc must return NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.

@@ -153,8 +153,6 @@
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */

-#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
-
/* basic functions */

extern const char * zlib_zlibVersion (void);
@@ -176,7 +174,7 @@

Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
- If zalloc and zfree are set to Z_NULL, deflateInit updates them to
+ If zalloc and zfree are set to NULL, deflateInit updates them to
use default allocation functions.

The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
@@ -298,11 +296,11 @@

Initializes the internal stream state for decompression. The fields
next_in, avail_in, and workspace must be initialized before by
- the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
+ the caller. If next_in is not NULL and avail_in is large enough (the exact
value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of
- inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ inflate. If zalloc and zfree are set to NULL, inflateInit updates them to
use default allocation functions.

inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
--- linux-2.5.70-bk11/include/linux/zutil.h~zlib_cleanup_Z_NULL 2003-06-06 19:50:47.000000000 +0200
+++ linux-2.5.70-bk11/include/linux/zutil.h 2003-06-06 20:16:34.000000000 +0200
@@ -81,7 +81,7 @@
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:

- uLong adler = adler32(0L, Z_NULL, 0);
+ uLong adler = adler32(0L, NULL, 0);

while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
@@ -96,7 +96,7 @@
unsigned long s2 = (adler >> 16) & 0xffff;
int k;

- if (buf == Z_NULL) return 1L;
+ if (buf == NULL) return 1L;

while (len > 0) {
k = len < NMAX ? len : NMAX;

2003-06-06 18:38:40

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib cleanup #4 casts

Hi Linus!

As promised, the NULL casts.

J?rn

--
Beware of bugs in the above code; I have only proved it correct, but
not tried it.
-- Donald Knuth

--- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_cleanup_casts 2003-06-06 20:14:27.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 20:44:51.000000000 +0200
@@ -962,7 +962,7 @@
#define FLUSH_BLOCK_ONLY(s, eof) { \
zlib_tr_flush_block(s, (s->block_start >= 0L ? \
(char *)&s->window[(unsigned)s->block_start] : \
- (char *)NULL), \
+ NULL), \
(ulg)((long)s->strstart - s->block_start), \
(eof)); \
s->block_start = s->strstart; \
--- linux-2.5.70-bk11/lib/zlib_inflate/infblock.c~zlib_cleanup_casts 2003-06-06 20:14:27.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/infblock.c 2003-06-06 20:45:51.000000000 +0200
@@ -80,7 +80,7 @@
s->bitb = 0;
s->read = s->write = s->window;
if (s->checkfn != NULL)
- z->adler = s->check = (*s->checkfn)(0L, (const Byte *)NULL, 0);
+ z->adler = s->check = (*s->checkfn)(0L, NULL, 0);
}

inflate_blocks_statef *zlib_inflate_blocks_new(
--- linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c~zlib_cleanup_casts 2003-06-06 20:14:27.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c 2003-06-06 20:47:11.000000000 +0200
@@ -139,7 +139,7 @@
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
- *t = (inflate_huft *)NULL;
+ *t = NULL;
*m = 0;
return Z_OK;
}
@@ -193,8 +193,8 @@
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
- u[0] = (inflate_huft *)NULL; /* just to keep compilers happy */
- q = (inflate_huft *)NULL; /* ditto */
+ u[0] = NULL; /* just to keep compilers happy */
+ q = NULL; /* ditto */
z = 0; /* ditto */

/* go through the bit lengths (k already is bits in shortest code) */
@@ -302,8 +302,7 @@
uInt *v; /* work area for huft_build */

v = WS(z)->tree_work_area_1;
- r = huft_build(c, 19, 19, (uInt*)NULL, (uInt*)NULL,
- tb, bb, hp, &hn, v);
+ r = huft_build(c, 19, 19, NULL, NULL, tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0)

2003-06-06 18:41:23

by Linus Torvalds

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib cleanup #3 Z_NULL


On Fri, 6 Jun 2003, J?rn Engel wrote:
>
> How do you feel about "if (z->state->blocks != NULL)"? Remove the
> pointless !=NULL or keep it?

I don't mind it, but it doesn't buy much.

It's actually in some other cases where I think there is a readability
issue, ie in more complex conditionals I personally prefer the simpler
cersion, ie I much prefer something like

if (ptr && ptr->ops && ptr->ops->shutdown)
ptr->ops->shutdown(ptr, xxxx);

over the pointless NULL-masturbation in something like

if (ptr != NULL && ptr->ops != NULL && ptr->ops->shutdown != NULL)
ptr->ops->shutdown(ptr, xxxx)

which I just is much less readable than the simple version.

Linus

2003-06-06 19:00:15

by Jörn Engel

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib cleanup #3 Z_NULL

On Fri, 6 June 2003 11:54:45 -0700, Linus Torvalds wrote:
> On Fri, 6 Jun 2003, J?rn Engel wrote:
> >
> > How do you feel about "if (z->state->blocks != NULL)"? Remove the
> > pointless !=NULL or keep it?
>
> I don't mind it, but it doesn't buy much.
>
> It's actually in some other cases where I think there is a readability
> issue, ie in more complex conditionals I personally prefer the simpler
> cersion, ie I much prefer something like
>
> if (ptr && ptr->ops && ptr->ops->shutdown)
> ptr->ops->shutdown(ptr, xxxx);
>
> over the pointless NULL-masturbation in something like
>
> if (ptr != NULL && ptr->ops != NULL && ptr->ops->shutdown != NULL)
> ptr->ops->shutdown(ptr, xxxx)
>
> which I just is much less readable than the simple version.

Good example. The ones I found in the zlib are not that bad and I am
lazy, so I'll leave them for someone else.

J?rn

--
Courage is not the absence of fear, but rather the judgement that
something else is more important than fear.
-- Ambrose Redmoon

2003-06-06 19:09:59

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib merge #1 turboc

Hi Linus!

This is the first bit of the missing merge towards 1.1.4. Applies on
top of the previous cleanups.

This one rips out an ugly #ifdef and seems to catch a theoretical
error possibility. Always thought that they fixed more than they
officially admitted.

J?rn

--
A victorious army first wins and then seeks battle.
-- Sun Tzu

--- linux-2.5.70-bk11/lib/zlib_inflate/infcodes.c~zlib_merge_turboc 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/infcodes.c 2003-06-06 21:18:16.000000000 +0200
@@ -149,15 +149,9 @@
DUMPBITS(j)
c->mode = COPY;
case COPY: /* o: copying bytes in window, waiting for space */
-#ifndef __TURBOC__ /* Turbo C bug for following expression */
- f = (uInt)(q - s->window) < c->sub.copy.dist ?
- s->end - (c->sub.copy.dist - (q - s->window)) :
- q - c->sub.copy.dist;
-#else
f = q - c->sub.copy.dist;
- if ((uInt)(q - s->window) < c->sub.copy.dist)
- f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
-#endif
+ while (f < s->window) /* modulo window size-"while" instead */
+ f += s->end - s->window; /* of "if" handles invalid distances */
while (c->len)
{
NEEDOUT

2003-06-06 19:14:42

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib merge #2 return code

Hi Linus!

Don't think anyone actually bothers to check specific error codes, but
it shouldn't hurt either.

J?rn

--
A surrounded army must be given a way out.
-- Sun Tzu

--- linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c~zlib_merge_return 2003-06-06 20:47:11.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inftrees.c 2003-06-06 21:25:10.000000000 +0200
@@ -229,7 +229,7 @@

/* allocate new table */
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
- return Z_MEM_ERROR; /* not enough memory */
+ return Z_DATA_ERROR; /* overflow of MANY */
u[h] = q = hp + *hn;
*hn += z;

2003-06-06 19:47:33

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib merge #3 inffast.c

Hi Linus!

This patch took me only 30 minutes to verify, too easy! :)

Most of it is reformatting, but the functional bits should fix real
problems. A loop is introduced, just like in the turboc patch and one
of the three condition bodies has been expanded.

J?rn

--
Fancy algorithms are slow when n is small, and n is usually small.
Fancy algorithms have big constants. Until you know that n is
frequently going to be big, don't get fancy.
-- Rob Pike

--- linux-2.5.70-bk11/lib/zlib_inflate/inffast.c~zlib_merge_inffast 2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inffast.c 2003-06-06 21:53:50.000000000 +0200
@@ -90,28 +90,41 @@

/* do the copy */
m -= c;
- if ((uInt)(q - s->window) >= d) /* offset before dest */
- { /* just copy */
- r = q - d;
- *q++ = *r++; c--; /* minimum count is three, */
- *q++ = *r++; c--; /* so unroll loop a little */
- }
- else /* else offset after destination */
+ r = q - d;
+ if (r < s->window) /* wrap if needed */
{
- e = d - (uInt)(q - s->window); /* bytes from offset to end */
- r = s->end - e; /* pointer to offset */
- if (c > e) /* if source crosses, */
+ do {
+ r += s->end - s->window; /* force pointer in window */
+ } while (r < s->window); /* covers invalid distances */
+ e = s->end - r;
+ if (c > e)
{
- c -= e; /* copy to end of window */
+ c -= e; /* wrapped copy */
do {
- *q++ = *r++;
+ *q++ = *r++;
} while (--e);
- r = s->window; /* copy rest from start of window */
+ r = s->window;
+ do {
+ *q++ = *r++;
+ } while (--c);
+ }
+ else /* normal copy */
+ {
+ *q++ = *r++; c--;
+ *q++ = *r++; c--;
+ do {
+ *q++ = *r++;
+ } while (--c);
}
}
- do { /* copy all or what's left */
- *q++ = *r++;
- } while (--c);
+ else /* normal copy */
+ {
+ *q++ = *r++; c--;
+ *q++ = *r++; c--;
+ do {
+ *q++ = *r++;
+ } while (--c);
+ }
break;
}
else if ((e & 64) == 0)

2003-06-06 19:59:36

by Jörn Engel

[permalink] [raw]
Subject: [Patch] 2.5.70-bk11 zlib merge #4 pure magic

Hi Linus!

This one is pure magic, really. No comment and inspection of the code
doesn't show much either. But judging from the other changes, this
should also fix a real problem, at least a theoretical one.

The only code that could be bitten by this change is ppp, so I changed
that as well. Paulus, could you have a quick look at it?

J?rn

--
This above all: to thine own self be true.
-- Shakespeare

--- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_merge_magic 2003-06-06 20:44:51.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 22:05:30.000000000 +0200
@@ -216,7 +216,7 @@
windowBits = -windowBits;
}
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
- windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+ windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
return Z_STREAM_ERROR;
}
--- linux-2.5.70-bk11/include/linux/ppp-comp.h~zlib_merge_magic 2003-06-05 17:46:35.000000000 +0200
+++ linux-2.5.70-bk11/include/linux/ppp-comp.h 2003-06-06 22:07:08.000000000 +0200
@@ -182,7 +182,7 @@
#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
#define CILEN_DEFLATE 4 /* length of its config option */

-#define DEFLATE_MIN_SIZE 8
+#define DEFLATE_MIN_SIZE 9
#define DEFLATE_MAX_SIZE 15
#define DEFLATE_METHOD_VAL 8
#define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)

Subject: Re: [Patch] 2.5.70-bk11 zlib merge #4 pure magic


On Fri, 6 Jun 2003, [iso-8859-1] J?rn Engel wrote:

> Hi Linus!
>
> This one is pure magic, really. No comment and inspection of the code
> doesn't show much either. But judging from the other changes, this
> should also fix a real problem, at least a theoretical one.

Eee, no magic here :-).

from 1.1.4 ChangeLog:
"- force windowBits > 8 to avoid a bug in the encoder for a window size
of 256 bytes. (A complete fix will be available in 1.1.5)."

I guess complete fix is here:
http://www.cs.toronto.edu/~cosmin/pngtech/zlib-256win-bug.html

Regards,
--
Bartlomiej

> The only code that could be bitten by this change is ppp, so I changed
> that as well. Paulus, could you have a quick look at it?
>
> J?rn
>
> --
> This above all: to thine own self be true.
> -- Shakespeare
>
> --- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_merge_magic 2003-06-06 20:44:51.000000000 +0200
> +++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 22:05:30.000000000 +0200
> @@ -216,7 +216,7 @@
> windowBits = -windowBits;
> }
> if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
> - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
> + windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
> strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
> return Z_STREAM_ERROR;
> }
> --- linux-2.5.70-bk11/include/linux/ppp-comp.h~zlib_merge_magic 2003-06-05 17:46:35.000000000 +0200
> +++ linux-2.5.70-bk11/include/linux/ppp-comp.h 2003-06-06 22:07:08.000000000 +0200
> @@ -182,7 +182,7 @@
> #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
> #define CILEN_DEFLATE 4 /* length of its config option */
>
> -#define DEFLATE_MIN_SIZE 8
> +#define DEFLATE_MIN_SIZE 9
> #define DEFLATE_MAX_SIZE 15
> #define DEFLATE_METHOD_VAL 8
> #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)


2003-06-06 21:25:02

by J.C. Wren

[permalink] [raw]
Subject: Is there a bug with su, and /dev/std*?

I was writing a script that writes to /dev/error, and I'm experiencing odd behavior. This is with a 2.4.18 kernel.

I login to an account, 'jcw'.

[jcw@drive jcw]$ echo test_msg >/dev/error
test_msg
[jcw@drive jcw]$ su - slimedr
Password:
[slimedr@drive jcw]$ echo test_msg >/dev/error
bash: /dev/stderr: Permission denied

As user 'jcw' we see

[jcw@drive jcw]$ ls -l /dev/stderr
lrwxrwxrwx 1 root root 17 Mar 11 15:28 /dev/stderr -> ../proc/self/fd/2
[jcw@drive jcw]$ ls -l /proc/self/fd/2
lrwx------ 1 jcw jcw 64 Jun 6 17:31 /proc/self/fd/2 -> /dev/pts/5

As user 'slimedr' we see

[slimedr@drive slimedr]$ ls -l /dev/stderr
lrwxrwxrwx 1 root root 17 Mar 11 15:28 /dev/stderr -> ../proc/self/fd/2
[slimedr@drive slimedr]$ ls -l /proc/self/fd/2
lrwx------ 1 slimedr slimedr 64 Jun 6 17:34 /proc/self/fd/2 -> /dev/pts/5

So what gives? Shouldn't the user context change with 'su -' allow me to write to /dev/stderr and /dev/stdout?

2003-06-07 09:07:10

by Jörn Engel

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib merge #4 pure magic

On Fri, 6 June 2003 22:36:07 +0200, Bartlomiej Zolnierkiewicz wrote:
> On Fri, 6 Jun 2003, [iso-8859-1] J?rn Engel wrote:
>
> > This one is pure magic, really. No comment and inspection of the code
> > doesn't show much either. But judging from the other changes, this
> > should also fix a real problem, at least a theoretical one.
>
> Eee, no magic here :-).
>
> from 1.1.4 ChangeLog:
> "- force windowBits > 8 to avoid a bug in the encoder for a window size
> of 256 bytes. (A complete fix will be available in 1.1.5)."

So there IS a ChangeLog. :)

> I guess complete fix is here:
> http://www.cs.toronto.edu/~cosmin/pngtech/zlib-256win-bug.html

> --- deflate.c Thu Jul 09 18:06:12 1998
> +++ deflate.c.fixed Thu Apr 12 04:02:36 2001
> @@ -242,7 +242,7 @@
> windowBits = -windowBits;
> }
> if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !=
> Z_DEFLATED ||
> - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
> + windowBits > 15 || level < 0 || level > 9 ||
> strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
> return Z_STREAM_ERROR;
> }

Completely removes the check.

> @@ -252,7 +252,11 @@
> s->strm = strm;
>
> s->noheader = noheader;
> - s->w_bits = windowBits;
> +#if MIN_LOOKAHEAD < 256
> + s->w_bits = (windowBits >= 8) ? windowBits : 8;
> +#else
> + s->w_bits = (windowBits >= 9) ? windowBits : 9;
> +#endif
> s->w_size = 1 << s->w_bits;
> s->w_mask = s->w_size - 1;

Now we don't check and inform the user anymore, instead we change the
value internally. So now overly smart users can set the windowBits to
a stupid value and we correct their mistake instead of telling them.
Not my preferred style.

> @@ -460,7 +464,12 @@
> /* Write the zlib header */
> if (s->status == INIT_STATE) {
>
> +#if MIN_LOOKAHEAD < 256
> uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
> +#else
> + uInt optimized_cinfo = (s->w_bits > 9) ? s->w_bits - 8 : 0;
> + uInt header = (Z_DEFLATED + (optimized_cinfo<<4)) << 8;
> +#endif
> uInt level_flags = (s->level-1) >> 1;
>
> if (level_flags > 3) level_flags = 3;

This changes one corner case where windowBits == 9. Even if the fix
is correct (too lazy to check), it costs us four new conditionals, of
which two were moved into the preprocessor. And the gain over patch
#4 is zero, since we waste the memory anyway, where windowBits is
too small for decent compression or not. Rejected.


Still, thanks for the two pointers, Bartlomiej! Not quite as magic
anymore. :)

J?rn

--
With a PC, I always felt limited by the software available. On Unix,
I am limited only by my knowledge.
-- Peter J. Schoenster

2003-06-07 09:30:15

by Paul Mackerras

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib merge #4 pure magic

J?rn Engel writes:

> The only code that could be bitten by this change is ppp, so I changed
> that as well. Paulus, could you have a quick look at it?

As Bart pointed out, there is a bug in zlib for window_size == 256.
Here is James Carlson's description of the problem:

The problem is that s->strstart gets set to a very large
positive integer when wsize (local copy of s->w_size) is
subtracted in deflate.c:fill_window(). This happens because
MAX_DIST(s) resolves as a negative number when the window size
is 8 -- MAX_DIST(s) is defined as s->w_size-MIN_LOOKAHEAD in
deflate.h. MIN_LOOKAHEAD is MAX_MATCH+MIN_MATCH+1, and that
is 258+3+1 or 262. Since a window size of 8 gives s->w_size
256, MAX_DIST(s) is 256-262 or -6.

This results in read_buf() writing over memory outside of
s->window, and a crash.

Your change won't affect PPP, since pppd already refuses to use
windowBits == 8 (as a workaround for this bug).

Regards,
Paul.

2003-06-07 09:48:55

by Jörn Engel

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib merge #4 pure magic

On Sat, 7 June 2003 19:40:25 +1000, Paul Mackerras wrote:
>
> Your change won't affect PPP, since pppd already refuses to use
> windowBits == 8 (as a workaround for this bug).

Seems like I have misread the ppp code then. In that case, please
remove the ppp part from the previous patch or use this one instead,
Linus.

J?rn

--
A defeated army first battles and then seeks victory.
-- Sun Tzu

--- linux-2.5.70-bk11/lib/zlib_deflate/deflate.c~zlib_merge_magic 2003-06-06 20:44:51.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_deflate/deflate.c 2003-06-06 22:05:30.000000000 +0200
@@ -216,7 +216,7 @@
windowBits = -windowBits;
}
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
- windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+ windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
return Z_STREAM_ERROR;
}

2003-06-07 11:44:52

by Paul Mackerras

[permalink] [raw]
Subject: Re: [Patch] 2.5.70-bk11 zlib merge #4 pure magic

J?rn Engel writes:

> On Sat, 7 June 2003 19:40:25 +1000, Paul Mackerras wrote:
> >
> > Your change won't affect PPP, since pppd already refuses to use
> > windowBits == 8 (as a workaround for this bug).
>
> Seems like I have misread the ppp code then. In that case, please
> remove the ppp part from the previous patch or use this one instead,
> Linus.

I meant that pppd (i.e. the user-level part of PPP) would refuse to
negotiate windowBits == 8 with the peer, so from that point of view it
doesn't matter if the kernel driver accepts it or not, since it will
never be asked to accept it (by pppd). It is better on the whole if
the kernel driver doesn't accept it since that is one less exploitable
thing in the kernel (although you would have to be root to exploit
it). But if the zlib code also refuses to use windowBits == 8, it
then doesn't matter whether the ppp_deflate code accepts it, from
either point of view.

On the whole I would say that the change to ppp-comp.h should go in,
for now at least.

Paul.