Haivision / srtgo

Go bindings for SRT. Advantages of SRT technology for an easy to use programming language
Mozilla Public License 2.0
185 stars 52 forks source link

Fix Read operation return value must be >= 0 #48

Closed jbreich closed 2 years ago

jbreich commented 2 years ago

I noticed that when using the library with bufio I get a segfault when the connection is closed. This is due to the returned value from the Read operation which is negative. Indeed, bufio is protected against that: https://github.com/golang/go/blob/master/src/bufio/bufio.go#L108 Also, from the Read documentation, n should be 0 <= n <= len(p) (https://github.com/golang/go/blob/master/src/io/io.go#L58)

The modification I have done is really simple, it is just re-assigning n to zero in case of error (negative value)

jeoliva commented 2 years ago

@jbreich, thanks for the PR. Should we do the same on srtSendMsg2Impl to keep consistency?

jbreich commented 2 years ago

You are right I am doing the modification

jeoliva commented 2 years ago

Huge thanks!