Fix nil pointer dereference

This commit is contained in:
Ingo Oppermann 2024-07-11 12:33:51 +02:00
parent 7e90bb87ce
commit cb9ce6f1dc
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
2 changed files with 56 additions and 1 deletions

View File

@ -68,7 +68,13 @@ func (p *ProgressIO) UnmarshalParser(pp *parse.ProgressIO) {
p.Sampling = pp.Sampling
p.Layout = pp.Layout
p.Channels = pp.Channels
p.AVstream.UnmarshalParser(pp.AVstream)
if pp.AVstream != nil {
p.AVstream = &AVstream{}
p.AVstream.UnmarshalParser(pp.AVstream)
} else {
p.AVstream = nil
}
}
func (p *ProgressIO) MarshalParser() parse.ProgressIO {

View File

@ -0,0 +1,49 @@
package app
import (
"testing"
"github.com/datarhei/core/v16/ffmpeg/parse"
"github.com/stretchr/testify/require"
)
func TestProgressIO(t *testing.T) {
original := parse.ProgressIO{
Address: "",
Index: 0,
Stream: 0,
Format: "",
Type: "",
Codec: "",
Coder: "",
Frame: 0,
Keyframe: 0,
Framerate: struct {
Min float64
Max float64
Average float64
}{},
FPS: 0,
Packet: 0,
PPS: 0,
Size: 0,
Bitrate: 0,
Extradata: 0,
Pixfmt: "",
Quantizer: 0,
Width: 0,
Height: 0,
Sampling: 0,
Layout: "",
Channels: 0,
AVstream: &parse.AVstream{},
}
p := ProgressIO{
AVstream: nil,
}
p.UnmarshalParser(&original)
restored := p.MarshalParser()
require.Equal(t, original, restored)
}