From 8002687dfafcfbc98abb3a8009e548f5ec97d212 Mon Sep 17 00:00:00 2001 From: Michel Machado Date: Wed, 1 Mar 2023 14:19:44 -0500 Subject: [PATCH] gt: fix l_lpm_lookup() and l_lpm6_lookup() This commit makes l_lpm_lookup() and l_lpm6_lookup() report error codes. This commit closes #632. --- gt/lua_lpm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gt/lua_lpm.c b/gt/lua_lpm.c index e3e3b706..1f82c684 100644 --- a/gt/lua_lpm.c +++ b/gt/lua_lpm.c @@ -252,9 +252,7 @@ l_lpm_lookup(lua_State *l) } ret = fib_lookup(&lpm_ud->fib, (uint8_t *)&ip, &label); - if (ret < 0) - lua_pushinteger(l, ret); - lua_pushinteger(l, label); + lua_pushinteger(l, ret >= 0 ? (lua_Integer)label : ret); return 1; } @@ -505,9 +503,7 @@ l_lpm6_lookup(lua_State *l) } ret = fib_lookup(&lpm6_ud->fib, ipv6_addr->s6_addr, &label); - if (ret < 0) - lua_pushinteger(l, ret); - lua_pushinteger(l, label); + lua_pushinteger(l, ret >= 0 ? (lua_Integer)label : ret); return 1; }