Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] Fix static buffer align
@ 2018-04-09  6:55 AKhatskevich
  2018-04-09 20:21 ` [tarantool-patches] " Konstantin Osipov
  0 siblings, 1 reply; 2+ messages in thread
From: AKhatskevich @ 2018-04-09  6:55 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tarantool-patches] Re: [PATCH] Fix static buffer align
  2018-04-09  6:55 [tarantool-patches] [PATCH] Fix static buffer align AKhatskevich
@ 2018-04-09 20:21 ` Konstantin Osipov
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Osipov @ 2018-04-09 20:21 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

* AKhatskevich <avkhatskevich@tarantool.org> [18/04/09 10:35]:

This is OK to push.

> 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
> 
> 

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-09 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09  6:55 [tarantool-patches] [PATCH] Fix static buffer align AKhatskevich
2018-04-09 20:21 ` [tarantool-patches] " Konstantin Osipov

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