From bdb1e9382c7bc4df1d29c96dfae70559713ec7b3 Mon Sep 17 00:00:00 2001 From: Ivan Murashko Date: Mon, 21 Oct 2019 16:23:33 +0300 Subject: [PATCH] lib: big integers should not be treated as negative ones 0xffffffff00000000ULL mask does not take into consideration signed 32 bit integers and as result 2147483648 will be stored as -2147483648. Another mask should be used to correct the issue: 0xffffffff80000000ULL. It processes correctly the case of integers that are greater than 2147483647. There are several gdb tests below: (gdb) p ((unsigned long long)2147483648 & 0xffffffff80000000ULL) $1= 2147483648 (gdb) p ((unsigned long long)2147483647 & 0xffffffff80000000ULL) $2 = 0 (gdb) p ((unsigned long long)2147483646 & 0xffffffff80000000ULL) $3 = 0 (gdb) p ((unsigned long long)4147483646 & 0xffffffff80000000ULL) $4 = 2147483648 --- src/lib/srdb1/db_ut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/srdb1/db_ut.c b/src/lib/srdb1/db_ut.c index 39ac11d3793..f14e4592561 100644 --- a/src/lib/srdb1/db_ut.c +++ b/src/lib/srdb1/db_ut.c @@ -598,7 +598,7 @@ int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t *pvs) db_longlong2str(dbval->val.ll_val, ll_buf, &pv.rs.len); pv.rs.s = ll_buf; /* if it fits, also store as 32 bit integer*/ - if (! ((unsigned long long)dbval->val.ll_val & 0xffffffff00000000ULL)) { + if (! ((unsigned long long)dbval->val.ll_val & 0xffffffff80000000ULL)) { pv.flags |= PV_VAL_INT | PV_TYPE_INT; pv.ri = (int)dbval->val.ll_val; }