mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
387cfccee4
We want to forbid this pattern since, unlike the other log_*()
macros, log_debug() conditionally evaluates its arguments only if
debug-level logging is enabled. Thus, a call to
log_debug("%d", x++);
will only increment x if debugging logs are enabled, which is
probably not what the programmer intended.
One bug caused by this pattern was #30628.
This script detects log_debug( ) calls with any of E++, E--, ++E,
or --E in their arguments, where E is an arbitrary expression.
Closes ticket 30743.
30 lines
567 B
Plaintext
30 lines
567 B
Plaintext
// Look for use of expressions with side-effects inside of debug logs.
|
|
//
|
|
// This script detects expressions like ++E, --E, E++, and E-- inside of
|
|
// calls to log_debug().
|
|
//
|
|
// The log_debug() macro exits early if debug logging is not enabled,
|
|
// potentially causing problems if its arguments have side-effects.
|
|
|
|
@@
|
|
expression E;
|
|
@@
|
|
*log_debug(... , <+... --E ...+>, ... );
|
|
|
|
|
|
@@
|
|
expression E;
|
|
@@
|
|
*log_debug(... , <+... ++E ...+>, ... );
|
|
|
|
@@
|
|
expression E;
|
|
@@
|
|
*log_debug(... , <+... E-- ...+>, ... );
|
|
|
|
|
|
@@
|
|
expression E;
|
|
@@
|
|
*log_debug(... , <+... E++ ...+>, ... );
|