Browse code

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

Ivan Murashko authored on 21/10/2019 13:23:33
Showing 1 changed files
... ...
@@ -598,7 +598,7 @@ int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t *pvs)
598 598
 				db_longlong2str(dbval->val.ll_val, ll_buf, &pv.rs.len);
599 599
 				pv.rs.s = ll_buf;
600 600
 				/* if it fits, also store as 32 bit integer*/
601
-				if (! ((unsigned long long)dbval->val.ll_val & 0xffffffff00000000ULL)) {
601
+				if (! ((unsigned long long)dbval->val.ll_val & 0xffffffff80000000ULL)) {
602 602
 					pv.flags |= PV_VAL_INT | PV_TYPE_INT;
603 603
 					pv.ri = (int)dbval->val.ll_val;
604 604
 				}