From: Stanislav Zudin <szudin@tarantool.org>
To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com
Cc: Stanislav Zudin <szudin@tarantool.org>
Subject: [PATCH 10/13] sql: fixes an error in sqlSubInt64
Date: Fri, 15 Mar 2019 18:45:39 +0300 [thread overview]
Message-ID: <fea0fdea2b5b0550377aed2e3b3f808f284ede84.1552663061.git.szudin@tarantool.org> (raw)
In-Reply-To: <cover.1552663061.git.szudin@tarantool.org>
In-Reply-To: <cover.1552663061.git.szudin@tarantool.org>
---
src/box/sql/util.c | 54 +++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index 3786c5083..980932f3b 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -1260,6 +1260,25 @@ static u64 mod64(i64 v, bool is_signed)
return (u64)v;
}
+static enum arithmetic_result
+apply_sign(i64* pOut, u64 value, bool is_neg)
+{
+ if (is_neg) {
+ if (value > INT64_MIN_MOD)
+ return ATHR_OVERFLOW;
+ else if (value == INT64_MIN_MOD)
+ *pOut = (i64)value;
+ else
+ *pOut = -(i64)value;
+
+ return ATHR_SIGNED;
+ }
+
+ *pOut = (i64) value;
+ return (value > INT64_MAX) ? ATHR_UNSIGNED
+ : ATHR_SIGNED;
+}
+
/*
* Attempt to add, substract, or multiply the 64-bit value iB against
* the other 64-bit integer at *pA and store the result in *pA.
@@ -1351,32 +1370,17 @@ sqlSubInt64(i64 * pA, bool is_signedA, i64 iB, bool is_signedB)
return sqlAddInt64(pA, is_signedA, uB, is_signedB);
} else {
/* Both iA & iB are positive */
- if ((u64)iA < (u64)iB)
- return ATHR_OVERFLOW;
- u64 val = (u64)iA - (u64)iB;
- *pA = (i64)val;
- return (val > INT64_MAX) ? ATHR_UNSIGNED
- : ATHR_SIGNED;
- }
-}
-
-static enum arithmetic_result
-apply_sign(i64* pOut, u64 value, bool is_neg)
-{
- if (is_neg) {
- if (value > INT64_MIN_MOD)
- return ATHR_OVERFLOW;
- else if (value == INT64_MIN_MOD)
- *pOut = (i64)value;
- else
- *pOut = -(i64)value;
-
- return ATHR_SIGNED;
+ if ((u64)iA < (u64)iB) {
+ /* subtract with sign changing */
+ u64 val = (u64)iB - (u64)iA;
+ return apply_sign(pA, val, true);
+ } else {
+ u64 val = (u64)iA - (u64)iB;
+ *pA = (i64)val;
+ return (val > INT64_MAX) ? ATHR_UNSIGNED
+ : ATHR_SIGNED;
+ }
}
-
- *pOut = (i64) value;
- return (value > INT64_MAX) ? ATHR_UNSIGNED
- : ATHR_SIGNED;
}
enum arithmetic_result
--
2.17.1
next prev parent reply other threads:[~2019-03-15 15:45 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 15:45 [PATCH 00/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-15 15:45 ` [PATCH 01/13] sql: Convert big integers from string Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-04-02 7:27 ` Konstantin Osipov
2019-03-15 15:45 ` [PATCH 02/13] sql: make VDBE recognize big integers Stanislav Zudin
2019-03-25 15:11 ` [tarantool-patches] " n.pettik
2019-04-01 20:42 ` Stanislav Zudin
2019-04-02 7:38 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 03/13] sql: removes unused function Stanislav Zudin
2019-03-25 15:11 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-03-15 15:45 ` [PATCH 04/13] sql: support big integers within sql binding Stanislav Zudin
2019-03-25 15:12 ` [tarantool-patches] " n.pettik
2019-04-01 20:42 ` Stanislav Zudin
2019-04-02 7:46 ` Konstantin Osipov
2019-04-02 7:44 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 05/13] sql: removes redundant function Stanislav Zudin
2019-03-25 15:12 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 06/13] sql: aux functions to support big integers Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 07/13] sql: arithmetic functions " Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:54 ` Konstantin Osipov
2019-04-02 7:52 ` Konstantin Osipov
2019-03-15 15:45 ` [PATCH 08/13] sql: aggregate sql functions support big int Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:57 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 09/13] sql: fixes errors Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` Stanislav Zudin [this message]
2019-03-25 15:14 ` [tarantool-patches] Re: [PATCH 10/13] sql: fixes an error in sqlSubInt64 n.pettik
2019-03-15 15:45 ` [PATCH 11/13] sql: fixes an error in string to int64 conversion Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 12/13] sql: fixes an error in uint64 to double casting Stanislav Zudin
2019-03-25 15:15 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 13/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-25 15:25 ` [tarantool-patches] " n.pettik
2019-04-01 20:44 ` Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] Re: [PATCH 00/13] " n.pettik
2019-04-01 20:38 ` Stanislav Zudin
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=fea0fdea2b5b0550377aed2e3b3f808f284ede84.1552663061.git.szudin@tarantool.org \
--to=szudin@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH 10/13] sql: fixes an error in sqlSubInt64' \
/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