From 6d14b4e439aec3d046addfa776a4be5f471a33f0 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 8 Dec 2023 10:20:14 +0100 Subject: [PATCH] lib/srdb1: rework store of long long values as number if value fits - GH #2106 --- src/lib/srdb1/db_ut.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/srdb1/db_ut.c b/src/lib/srdb1/db_ut.c index c7a8887044e..9975672aeea 100644 --- a/src/lib/srdb1/db_ut.c +++ b/src/lib/srdb1/db_ut.c @@ -610,11 +610,16 @@ int db_val2pv_spec(struct sip_msg *msg, db_val_t *dbval, pv_spec_t *pvs) pv.rs.len = LL_LEN; 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 it fits, also store as long number */ + if(sizeof(long long) == sizeof(long)) { pv.flags |= PV_VAL_INT | PV_TYPE_INT; - pv.ri = (int)dbval->val.ll_val; + pv.ri = (long)dbval->val.ll_val; + } else { + if(dbval->val.ll_val >= LONG_MIN + && dbval->val.ll_val <= LONG_MAX) { + pv.flags |= PV_VAL_INT | PV_TYPE_INT; + pv.ri = (long)dbval->val.ll_val; + } } break; default: