From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id BAFDE201D0 for ; Mon, 9 Apr 2018 02:55:58 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nbt-okrmaE4A for ; Mon, 9 Apr 2018 02:55:58 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 1DAAC1FBCC for ; Mon, 9 Apr 2018 02:55:57 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH] Fix static buffer align Date: Mon, 9 Apr 2018 09:55:40 +0300 Message-Id: <20180409065540.22360-1-avkhatskevich@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: v.shpilevoy@tarantool.org Cc: tarantool-patches@freelists.org Branch: https://github.com/tarantool/tarantool/tree/kh/align_static_buf The length of the TT_STATIC_BUFS was 1025 bytes which lead to unaligned allocation. The addresses was allocated like this: - 0 0x7ffdd80aaa20 - 1 0x7ffdd80aae21 - 2 0x7ffdd80ab222 - 3 0x7ffdd80ab623 It may affect the performance and looks wired. --- src/trivia/util.h | 2 +- src/tt_uuid.c | 2 +- src/tt_uuid.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/trivia/util.h b/src/trivia/util.h index 38beff395..8f2075664 100644 --- a/src/trivia/util.h +++ b/src/trivia/util.h @@ -489,7 +489,7 @@ static inline char * tt_static_buf(void) { enum { TT_STATIC_BUFS = 4 }; - static __thread char bufs[TT_STATIC_BUFS][TT_STATIC_BUF_LEN + 1]; + static __thread char bufs[TT_STATIC_BUFS][TT_STATIC_BUF_LEN]; static __thread int bufno = TT_STATIC_BUFS - 1; bufno = (bufno + 1) % TT_STATIC_BUFS; diff --git a/src/tt_uuid.c b/src/tt_uuid.c index f621ba711..530aa31a1 100644 --- a/src/tt_uuid.c +++ b/src/tt_uuid.c @@ -86,7 +86,7 @@ tt_uuid_is_equal(const struct tt_uuid *lhs, const struct tt_uuid *rhs); char * tt_uuid_str(const struct tt_uuid *uu) { - assert(TT_STATIC_BUF_LEN >= UUID_STR_LEN); + assert(TT_STATIC_BUF_LEN > UUID_STR_LEN); char *buf = tt_static_buf(); tt_uuid_to_string(uu, buf); return buf; diff --git a/src/tt_uuid.h b/src/tt_uuid.h index 818914b83..00d6de662 100644 --- a/src/tt_uuid.h +++ b/src/tt_uuid.h @@ -124,7 +124,8 @@ tt_uuid_compare(const struct tt_uuid *a, const struct tt_uuid *b) inline void tt_uuid_to_string(const struct tt_uuid *uu, char *out) { - sprintf(out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + snprintf(out, UUID_STR_LEN + 1, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", uu->time_low, uu->time_mid, uu->time_hi_and_version, uu->clock_seq_hi_and_reserved, uu->clock_seq_low, uu->node[0], uu->node[1], uu->node[2], uu->node[3], uu->node[4], uu->node[5]); -- 2.14.1