[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: ITS#6101 Uninitialized SlapReply components



hyc@symas.com writes:
> What do you mean by "components are commonly used uninitialized" ?
> Have you actually seen cases where the code reads these values before
> they are init'd?  Certainly valgrind never trips over them.

There is nothing for Valgrind to trip over if the compiler zero-fills
rs.sr_un union when it sees
	SlapReply rs = {REP_RESULT};

However, add this in slap.h, which is all the compiler needs to emit
for that initialization:

#define DECL_SlapReply(name, type) \
	SlapReply	name;	\
	name.sr_type = 0;	\
	name.sr_tag = 0;	\
	name.sr_msgid = 0;	\
	name.sr_err = 0;	\
	name.sr_matched = 0;\
	name.sr_text = 0;	\
	name.sr_ref = 0;	\
	name.sr_ctrls = 0;	\
	name.sr_un.sru_sasl.r_sasldata = 0; \
	name.sr_flags = 0

Replace current initializations with that as follows:

grep -l 'SlapReply[<tab> ][a-z0-9]* *=' *.c */*.c | xargs perl -i -pe '
	s/^(\t+)(SlapReply)\s+(\w+)\s*=\s*{\s*(\w+)\s*}\;/$1DECL_$2($3, $4)\;/'

(type ctrl-v tab in shell for the<tab>)

Compile with C99 or gcc extension mode to allow mixed code and decls.

make test doesn't even survive test000.  And yes, valgrind is annoyed.

-- 
Hallvard