Browse code

pv: log uninit $var()

Stefan Mititelu authored on 17/05/2022 10:07:06
Showing 2 changed files
... ...
@@ -2597,6 +2597,11 @@ int pv_get_scriptvar(struct sip_msg *msg,  pv_param_t *param,
2597 2597
 		res->ri = sv->v.value.n;
2598 2598
 		res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
2599 2599
 	}
2600
+
2601
+	if (!sv->init) {
2602
+		LM_WARN("Script variable \"$var(%.*s)\" used uninitialized!\n", sv->name.len, sv->name.s);
2603
+	}
2604
+
2600 2605
 	return 0;
2601 2606
 }
2602 2607
 
... ...
@@ -2899,6 +2904,10 @@ int pv_set_scriptvar(struct sip_msg* msg, pv_param_t *param,
2899 2904
 		LM_ERR("error - cannot find svar\n");
2900 2905
 		goto error;
2901 2906
 	}
2907
+
2908
+	script_var_t *sv = (param->pvn.u.dname);
2909
+	sv->init = 1;
2910
+
2902 2911
 	if((val==NULL) || (val->flags&PV_VAL_NULL))
2903 2912
 	{
2904 2913
 		if(((script_var_t*)param->pvn.u.dname)->v.flags&VAR_TYPE_NULL)
... ...
@@ -46,6 +46,7 @@ typedef struct script_var {
46 46
 	str name;
47 47
 	script_val_t v;
48 48
 	struct script_var *next;
49
+	int init;
49 50
 } script_var_t, *script_var_p;
50 51
 
51 52
 script_var_t* add_var(str *name, int vtype);