From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (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 C25A9469710 for ; Sat, 16 May 2020 02:03:53 +0300 (MSK) From: Vladislav Shpilevoy Date: Sat, 16 May 2020 01:03:50 +0200 Message-Id: <172feb69ec2caea2aa63a24de8b76a4dba13bebb.1589583614.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] uuid: fix unaligned memory access 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, alyapunov@tarantool.org Functions tt_uuid_is_nil() and tt_uuid_is_equal() used struct tt_uuid as an array of two uint64. But it is wrong, because struct tt_uuid has 4 byte alignment, while uint64 requires 8. That led to unaligned memory access in these 2 functions. The patch makes these functions treat struct tt_uuid as 4 uint32 instead of 2 uint64. Part of #4609 --- src/lib/uuid/tt_uuid.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/uuid/tt_uuid.h b/src/lib/uuid/tt_uuid.h index c2c436ed4..d62991c65 100644 --- a/src/lib/uuid/tt_uuid.h +++ b/src/lib/uuid/tt_uuid.h @@ -158,8 +158,8 @@ tt_uuid_bswap(struct tt_uuid *uu) inline bool tt_uuid_is_nil(const struct tt_uuid *uu) { - const uint64_t *p = (const uint64_t *) uu; - return !p[0] && !p[1]; + const uint32_t *p = (const uint32_t *) uu; + return p[0] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0; } /** @@ -172,9 +172,10 @@ tt_uuid_is_nil(const struct tt_uuid *uu) inline bool tt_uuid_is_equal(const struct tt_uuid *lhs, const struct tt_uuid *rhs) { - const uint64_t *lp = (const uint64_t *) lhs; - const uint64_t *rp = (const uint64_t *) rhs; - return lp[0] == rp[0] && lp[1] == rp[1]; + const uint32_t *lp = (const uint32_t *) lhs; + const uint32_t *rp = (const uint32_t *) rhs; + return lp[0] == rp[0] && lp[1] == rp[1] && lp[2] == rp[2] && + lp[3] == rp[3]; } extern const struct tt_uuid uuid_nil; -- 2.21.1 (Apple Git-122.3)