[Tarantool-patches] [PATCH v6 21/22] sql: fix implicit cast in opcode MustBeInt
imeevma at tarantool.org
imeevma at tarantool.org
Thu Jul 16 17:47:19 MSK 2020
This patch removes implicit casting from STRING to number and vice
versa from MustBeInt opcode.
Part of #4230
---
src/box/sql/vdbe.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 73b25fecf..9b2b18a9a 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2349,16 +2349,20 @@ case OP_AddImm: { /* in1 */
*/
case OP_MustBeInt: { /* jump, in1 */
pIn1 = &aMem[pOp->p1];
- if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
- mem_apply_type(pIn1, FIELD_TYPE_INTEGER);
- if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
- if (pOp->p2==0) {
- diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
- sql_value_to_diag_str(pIn1), "integer");
- goto abort_due_to_error;
- } else {
- goto jump_to_p2;
- }
+ if (mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER))
+ break;
+ if ((pIn1->flags & MEM_Real) != 0) {
+ double d = pIn1->u.r;
+ if (d == (double)(int64_t)d || d == (double)(uint64_t)d)
+ mem_convert_to_integer(pIn1);
+ }
+ if (!mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER)) {
+ if (pOp->p2==0) {
+ diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+ sql_value_to_diag_str(pIn1), "integer");
+ goto abort_due_to_error;
+ } else {
+ goto jump_to_p2;
}
}
break;
--
2.25.1
More information about the Tarantool-patches
mailing list