[PATCH 6/7] Protect 'orig_len' in |recover_unused_bytes| by DBUS_ENABLE_VERBOSE_MODE

Thomas Zimmermann tdz at users.sourceforge.net
Mon Aug 15 15:47:13 UTC 2016


Hi!

Some thoughts on this problem: with gcc, one can do something like this:

#ifndef DEBUG
  __dbus_assert (condition)
	do {
		__typeof (!(condition)) val __attribute__((__unused__));
	} while (0)
#else
  // do debug
#endif

This should use the type of 'condition' without evaluating it. The
declared variable itself is unused. Unfortunately I don't know how to do
this with _dbus_verbose's VA args.

Maybe additional annotation can be used, like

#define DEBUG_OR(expression, default_value) \
	(DEBUG ? expression : default_value)

and called like this:

my_debug_value = DEBUG_OR(compute_val(), 0);

Here DEBUG is evaluated by the C compiler, so compute_val() doesn't have
to protected by DEBUG-based preprocessor guards.

Best regards
Thomas

Am 15.08.2016 um 13:17 schrieb Simon McVittie:
> On 10/08/16 16:08, Thiago Macieira wrote:
>> One way I've solved this problem is to "use" the expression in even disabled 
>> asserts
> 
> That results in the expression's side-effects still happening: for
> instance if it calls a function, we pay the CPU cost of calling that
> function. I don't think we want that here.
> 


-- 
GnuPG:          http://tdz.users.sourceforge.net/tdz.asc
Fingerprint:    16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20160815/27bce6c4/attachment.sig>


More information about the dbus mailing list