[PATCH] lua: fix decimal comparison with box.NULL

Serge Petrenko sergepetrenko at tarantool.org
Tue Aug 27 14:22:09 MSK 2019


This problem is similar to the one fixed in commit
3c6c1cc96a1a510493c21c472565d4063e403ba2 (lua:fix decimal comparison
with nil)
We should handle box.NULL the same way.

Closes #4454
---
https://github.com/tarantool/tarantool/issues/4454
https://github.com/tarantool/tarantool/tree/sp/gh-4454-decimal-cmp-null

 src/lua/decimal.c         |  3 ++-
 test/app/decimal.result   | 30 ++++++++++++++++++++++++++++++
 test/app/decimal.test.lua |  8 ++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/lua/decimal.c b/src/lua/decimal.c
index 23e50ba68..8905a0b9d 100644
--- a/src/lua/decimal.c
+++ b/src/lua/decimal.c
@@ -235,7 +235,8 @@ static int
 ldecimal_eq(struct lua_State *L)
 {
 	assert(lua_gettop(L) == 2);
-	if (lua_isnil(L, 1) || lua_isnil(L, 2)) {
+	if (lua_isnil(L, 1) || lua_isnil(L, 2) ||
+	    luaL_isnull(L, 1) || luaL_isnull(L, 2)) {
 		lua_pushboolean(L, false);
 		return 1;
 	}
diff --git a/test/app/decimal.result b/test/app/decimal.result
index 8251e13d8..90d0984b0 100644
--- a/test/app/decimal.result
+++ b/test/app/decimal.result
@@ -248,6 +248,36 @@ a <= nil
  | ---
  | - error: '[string "return a <= nil "]:1: attempt to compare decimal with nil'
  | ...
+-- and with box.NULL
+--
+a == box.NULL
+ | ---
+ | - false
+ | ...
+a ~= box.NULL
+ | ---
+ | - true
+ | ...
+a > box.NULL
+ | ---
+ | - error: '[string "return a > box.NULL "]:1: expected decimal, number or string as
+ |     1 argument'
+ | ...
+a < box.NULL
+ | ---
+ | - error: '[string "return a < box.NULL "]:1: expected decimal, number or string as
+ |     2 argument'
+ | ...
+a >= box.NULL
+ | ---
+ | - error: '[string "return a >= box.NULL "]:1: expected decimal, number or string as
+ |     1 argument'
+ | ...
+a <= box.NULL
+ | ---
+ | - error: '[string "return a <= box.NULL "]:1: expected decimal, number or string as
+ |     2 argument'
+ | ...
 
 decimal.sqrt(a)
  | ---
diff --git a/test/app/decimal.test.lua b/test/app/decimal.test.lua
index d83522b45..79189a2f5 100644
--- a/test/app/decimal.test.lua
+++ b/test/app/decimal.test.lua
@@ -69,6 +69,14 @@ a > nil
 a < nil
 a >= nil
 a <= nil
+-- and with box.NULL
+--
+a == box.NULL
+a ~= box.NULL
+a > box.NULL
+a < box.NULL
+a >= box.NULL
+a <= box.NULL
 
 decimal.sqrt(a)
 decimal.ln(a)
-- 
2.20.1 (Apple Git-117)




More information about the Tarantool-patches mailing list