fix for callcost out of bounds merge (thanks DigiDaz)

This commit is contained in:
Radu Ioan Fericean
2014-04-23 13:23:58 +03:00
parent 2d042d65bf
commit 251d504d40
2 changed files with 13 additions and 1 deletions

View File

@@ -46,7 +46,7 @@ type CallCost struct {
// Merges the received timespan if they are similar (same activation period, same interval, same minute info.
func (cc *CallCost) Merge(other *CallCost) {
if len(cc.Timespans)-1 < 0 {
if len(cc.Timespans)-1 < 0 || len(other.Timespans) == 0 {
return
}
ts := cc.Timespans[len(cc.Timespans)-1]

View File

@@ -125,6 +125,18 @@ func TestMultipleInputRightMerge(t *testing.T) {
}
}
func TestCallCostMergeEmpty(t *testing.T) {
t1 := time.Date(2012, time.February, 2, 17, 58, 0, 0, time.UTC)
t2 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
cd := &CallDescriptor{Direction: OUTBOUND, TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
cc1, _ := cd.GetCost()
cc2 := &CallCost{}
cc1.Merge(cc2)
if len(cc1.Timespans) != 1 {
t.Error("Error mergin empty call cost: ", len(cc1.Timespans))
}
}
func TestCallCostGetDurationZero(t *testing.T) {
cc := &CallCost{}
if cc.GetDuration().Seconds() != 0 {