[Asterisk-code-review] RAII: Change order or variables in clang version (asterisk[master])

Diederik de Groot asteriskteam at digium.com
Sat Jan 5 11:17:56 CST 2019


Diederik de Groot has uploaded this change for review. ( https://gerrit.asterisk.org/10854


Change subject: RAII: Change order or variables in clang version
......................................................................

RAII: Change order or variables in clang version

This prevents use-after-scope issues when unrolling the stack,
which happens in reverse order.
Issue was found using clang + address-sanitizer.

Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
---
M include/asterisk/utils.h
1 file changed, 4 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/10854/1

diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c0cce98..4dc406d 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -786,10 +786,10 @@
 typedef void (^_raii_cleanup_block_t)(void);
 static inline void _raii_cleanup_block(_raii_cleanup_block_t *b) { (*b)(); }
 
-#define RAII_VAR(vartype, varname, initval, dtor)                                                                \
-    _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) = NULL; \
-    __block vartype varname = initval;                                                                           \
-    _raii_cleanup_ ## varname = ^{ {(void)dtor(varname);} }
+#define RAII_VAR(vartype, varname, initval, dtor)                                                              \
+    __block vartype varname = initval;                                                                         \
+    _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) =     \
+        ^{ {(void)dtor(varname);} };
 
 #elif defined(__GNUC__)
 

-- 
To view, visit https://gerrit.asterisk.org/10854
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
Gerrit-Change-Number: 10854
Gerrit-PatchSet: 1
Gerrit-Owner: Diederik de Groot <dkgroot at talon.nl>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190105/83d69915/attachment.html>


More information about the asterisk-code-review mailing list