Tarantool development patches archive
 help / color / mirror / Atom feed
From: AKhatskevich <avkhatskevich@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH] Fix static buffer align
Date: Mon,  9 Apr 2018 09:55:40 +0300	[thread overview]
Message-ID: <20180409065540.22360-1-avkhatskevich@tarantool.org> (raw)

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

             reply	other threads:[~2018-04-09  6:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  6:55 AKhatskevich [this message]
2018-04-09 20:21 ` [tarantool-patches] " Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180409065540.22360-1-avkhatskevich@tarantool.org \
    --to=avkhatskevich@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH] Fix static buffer align' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox