From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 22E8F469710 for ; Wed, 13 May 2020 02:27:28 +0300 (MSK) From: Vladislav Shpilevoy Date: Wed, 13 May 2020 01:27:25 +0200 Message-Id: <4a2553507fcf643e1e5bae0753d95ee4ff7d4253.1589325991.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH small 1/1] rlist: use built-in offsetof() when possible List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, tsafin@tarantool.org, gorcunov@gmail.com Rlist implemented its own offsetof() as a classic NULL pointer cast to the target type with taking address of the member. So it turned into NULL + member offset. But appeared undefined behaviour clang sanitizer is not friendly to this hack. The patch makes rlist define its own offsetof only as a last resort. Part of https://github.com/tarantool/tarantool/issues/4609 --- Branch: http://github.com/tarantool/small/tree/gerold103/rlist-offsetof Issue: https://github.com/tarantool/tarantool/issues/4609 small/rlist.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/small/rlist.h b/small/rlist.h index 2b0bcb4..26edd2e 100644 --- a/small/rlist.h +++ b/small/rlist.h @@ -40,6 +40,10 @@ extern "C" { #define typeof __typeof__ #endif +#ifndef offsetof +#define offsetof(type, member) ((size_t) &((type *)0)->member) +#endif + /** * list entry and head structure */ @@ -272,8 +276,9 @@ rlist_cut_before(struct rlist *head1, struct rlist *head2, struct rlist *item) * return entry by list item */ #define rlist_entry(item, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (item); \ - (type *)( (char *)__mptr - ((size_t) &((type *)0)->member) ); }) + const typeof(((type *)0)->member) *__mptr = (item); \ + (type *)( (char *)__mptr - offsetof(type,member)); \ +}) /** * return first entry -- 2.21.1 (Apple Git-122.3)