From 5c4795786e3a4ff0192d4ddebd2dda6f3c0c74cd Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 20:14:27 +1030 Subject: [PATCH] psi/helpers.go: modified UpdateLocation() to make updating of location in pmt cleaner, and also removed redundant conversion of string to byte slice --- stream/mts/psi/helpers.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/stream/mts/psi/helpers.go b/stream/mts/psi/helpers.go index 86e6cc72..82d7ce72 100644 --- a/stream/mts/psi/helpers.go +++ b/stream/mts/psi/helpers.go @@ -106,14 +106,11 @@ func UpdateLocation(d []byte, s string) error { if !HasLocation(d) { return errors.New("pmt does not location descriptor, cannot update") } - sb := []byte(s) - locBytes := d[LocationDataIndx : LocationDataIndx+LocationDataSize] - for i, _ := range locBytes { - if i < len(sb) { - locBytes[i] = sb[i] - } else { - locBytes[i] = 0x00 - } + loc := d[LocationDataIndx : LocationDataIndx+LocationDataSize] + n := copy(loc, s) + loc = loc[n:] + for i := range loc { + loc[i] = 0 } updateCrc(d) return nil