瀏覽代碼

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

- better access to branch structures
Daniel-Constantin Mierla 10 年之前
父節點
當前提交
6461b799ce
共有 1 個文件被更改,包括 10 次插入0 次删除
  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");
 			LM_ERR("invalid index\n");
 			return -1;
 			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);
 		br = get_sip_branch(idx);
 	}
 	}