Browse Source

pv: convert negative index to positive position for $branch(...)

- better access to branch structures
Daniel-Constantin Mierla 10 years ago
parent
commit
6461b799ce
1 changed files with 10 additions and 0 deletions
  1. 10 0
      modules/pv/pv_branch.c

+ 10 - 0
modules/pv/pv_branch.c

@@ -133,6 +133,16 @@ int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param,
 			LM_ERR("invalid index\n");
 			return -1;
 		}
+		if(idx<0)
+		{
+			if((int)nr_branches + idx >= 0) {
+				idx += nr_branches;
+			} else {
+				LM_ERR("index too low: %d (%u)\n", idx, nr_branches);
+				return -1;
+			}
+		}
+		LM_DBG("managing branch index %d (%u)\n", idx, nr_branches);
 		br = get_sip_branch(idx);
 	}