Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH 1/1] Fix SQL MEM-related warnings
@ 2021-04-19 16:03 Mergen Imeev via Tarantool-patches
  2021-04-22 23:12 ` Timur Safin via Tarantool-patches
  0 siblings, 1 reply; 2+ messages in thread
From: Mergen Imeev via Tarantool-patches @ 2021-04-19 16:03 UTC (permalink / raw)
  To: tsafin; +Cc: tarantool-patches

https://github.com/tarantool/tarantool/issues/5818
https://github.com/tarantool/tarantool/tree/imeevma/gh-5818-follow-up

---
 src/box/sql/func.c |  3 ++-
 src/box/sql/mem.c  | 11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 9c28d5122..8d81a2ed3 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -343,6 +343,7 @@ position_func(struct sql_context *context, int argc, struct Mem **argv)
 			 */
 			haystack_str = mem_as_ustr(haystack);
 			needle_str = mem_as_ustr(needle);
+			assert(needle_str != NULL && haystack_str != NULL);
 
 			int n_needle_chars =
 				sql_utf8_char_count(needle_str, n_needle_bytes);
@@ -569,7 +570,7 @@ roundFunc(sql_context * context, int argc, sql_value ** argv)
 	} else if (n == 0 && r < 0 && (-r) < (double)(LARGEST_INT64 - 1)) {
 		r = -(double)((sql_int64) ((-r) + 0.5));
 	} else {
-		const char *rounded_value = tt_sprintf("%.*f", n, r);
+		const char *rounded_value = tt_sprintf("%.*f", (int)n, r);
 		sqlAtoF(rounded_value, &r, sqlStrlen30(rounded_value));
 	}
 	sql_result_double(context, r);
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index b6ff6397f..0f41ba0d8 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -70,7 +70,7 @@ mem_str(const struct Mem *mem)
 	case MEM_Int:
 		return tt_sprintf("%lld", mem->u.i);
 	case MEM_UInt:
-		return tt_sprintf("%llu", mem->u.u);
+		return tt_sprintf("%lu", mem->u.u);
 	case MEM_Real:
 		sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r);
 		return tt_sprintf("%s", buf);
@@ -520,7 +520,7 @@ int_to_str0(struct Mem *mem)
 {
 	const char *str;
 	if ((mem->flags & MEM_UInt) != 0)
-		str = tt_sprintf("%llu", mem->u.u);
+		str = tt_sprintf("%lu", mem->u.u);
 	else
 		str = tt_sprintf("%lld", mem->u.i);
 	return mem_copy_str0(mem, str);
@@ -729,7 +729,8 @@ double_to_bool(struct Mem *mem)
 static inline int
 bool_to_int(struct Mem *mem)
 {
-	mem->u.u = (uint64_t)mem->u.b;
+	uint64_t u = (uint64_t)mem->u.b;
+	mem->u.u = u;
 	mem->flags = MEM_UInt;
 	mem->field_type = FIELD_TYPE_UNSIGNED;
 	return 0;
@@ -1599,7 +1600,7 @@ mem_shift_left(const struct Mem *left, const struct Mem *right,
 		result->u.i = a >= 0 ? 0 : -1;
 	else if (b < 0)
 		result->u.i = a >> -b;
-	else if (b > 64)
+	else if (b >= 64)
 		result->u.i = 0;
 	else
 		result->u.i = a << b;
@@ -1621,7 +1622,7 @@ mem_shift_right(const struct Mem *left, const struct Mem *right,
 		result->u.i = 0;
 	else if (b < 0)
 		result->u.i = a << -b;
-	else if (b > 64)
+	else if (b >= 64)
 		result->u.i = a >= 0 ? 0 : -1;
 	else
 		result->u.i = a >> b;
-- 
2.25.1


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

* Re: [Tarantool-patches] [PATCH 1/1] Fix SQL MEM-related warnings
  2021-04-19 16:03 [Tarantool-patches] [PATCH 1/1] Fix SQL MEM-related warnings Mergen Imeev via Tarantool-patches
@ 2021-04-22 23:12 ` Timur Safin via Tarantool-patches
  0 siblings, 0 replies; 2+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-04-22 23:12 UTC (permalink / raw)
  To: imeevma; +Cc: tarantool-patches

Could you please put to the description some brief explanation which
problems do you fix here? (link to analysis is preferred, but if it's 
not generally accessible then excerpts from report would be enough)

At the moment it's not entirely clear which problems here fixed.

Thanks,
Timur

: -----Original Message-----
: From: imeevma@tarantool.org <imeevma@tarantool.org>
: Sent: Monday, April 19, 2021 7:04 PM
: To: tsafin@tarantool.org
: Cc: tarantool-patches@dev.tarantool.org
: Subject: [PATCH 1/1] Fix SQL MEM-related warnings
: 
: https://github.com/tarantool/tarantool/issues/5818
: https://github.com/tarantool/tarantool/tree/imeevma/gh-5818-follow-up
: 
: ---
:  src/box/sql/func.c |  3 ++-
:  src/box/sql/mem.c  | 11 ++++++-----
:  2 files changed, 8 insertions(+), 6 deletions(-)
: 
: diff --git a/src/box/sql/func.c b/src/box/sql/func.c
: index 9c28d5122..8d81a2ed3 100644
: --- a/src/box/sql/func.c
: +++ b/src/box/sql/func.c
: @@ -343,6 +343,7 @@ position_func(struct sql_context *context, int argc,
: struct Mem **argv)
:  			 */
:  			haystack_str = mem_as_ustr(haystack);
:  			needle_str = mem_as_ustr(needle);
: +			assert(needle_str != NULL && haystack_str != NULL);
: 
:  			int n_needle_chars =
:  				sql_utf8_char_count(needle_str, n_needle_bytes);
: @@ -569,7 +570,7 @@ roundFunc(sql_context * context, int argc, sql_value **
: argv)
:  	} else if (n == 0 && r < 0 && (-r) < (double)(LARGEST_INT64 - 1)) {
:  		r = -(double)((sql_int64) ((-r) + 0.5));
:  	} else {
: -		const char *rounded_value = tt_sprintf("%.*f", n, r);
: +		const char *rounded_value = tt_sprintf("%.*f", (int)n, r);
:  		sqlAtoF(rounded_value, &r, sqlStrlen30(rounded_value));
:  	}
:  	sql_result_double(context, r);
: diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
: index b6ff6397f..0f41ba0d8 100644
: --- a/src/box/sql/mem.c
: +++ b/src/box/sql/mem.c
: @@ -70,7 +70,7 @@ mem_str(const struct Mem *mem)
:  	case MEM_Int:
:  		return tt_sprintf("%lld", mem->u.i);
:  	case MEM_UInt:
: -		return tt_sprintf("%llu", mem->u.u);
: +		return tt_sprintf("%lu", mem->u.u);
:  	case MEM_Real:
:  		sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r);
:  		return tt_sprintf("%s", buf);
: @@ -520,7 +520,7 @@ int_to_str0(struct Mem *mem)
:  {
:  	const char *str;
:  	if ((mem->flags & MEM_UInt) != 0)
: -		str = tt_sprintf("%llu", mem->u.u);
: +		str = tt_sprintf("%lu", mem->u.u);
:  	else
:  		str = tt_sprintf("%lld", mem->u.i);
:  	return mem_copy_str0(mem, str);
: @@ -729,7 +729,8 @@ double_to_bool(struct Mem *mem)
:  static inline int
:  bool_to_int(struct Mem *mem)
:  {
: -	mem->u.u = (uint64_t)mem->u.b;
: +	uint64_t u = (uint64_t)mem->u.b;
: +	mem->u.u = u;
:  	mem->flags = MEM_UInt;
:  	mem->field_type = FIELD_TYPE_UNSIGNED;
:  	return 0;
: @@ -1599,7 +1600,7 @@ mem_shift_left(const struct Mem *left, const struct
: Mem *right,
:  		result->u.i = a >= 0 ? 0 : -1;
:  	else if (b < 0)
:  		result->u.i = a >> -b;
: -	else if (b > 64)
: +	else if (b >= 64)
:  		result->u.i = 0;
:  	else
:  		result->u.i = a << b;
: @@ -1621,7 +1622,7 @@ mem_shift_right(const struct Mem *left, const struct
: Mem *right,
:  		result->u.i = 0;
:  	else if (b < 0)
:  		result->u.i = a << -b;
: -	else if (b > 64)
: +	else if (b >= 64)
:  		result->u.i = a >= 0 ? 0 : -1;
:  	else
:  		result->u.i = a >> b;
: --
: 2.25.1



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

end of thread, other threads:[~2021-04-22 23:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 16:03 [Tarantool-patches] [PATCH 1/1] Fix SQL MEM-related warnings Mergen Imeev via Tarantool-patches
2021-04-22 23:12 ` Timur Safin via Tarantool-patches

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