Closed elgohr closed 3 months ago
Hi, the current implementation of ReadByte takes a pointer to a byte as an argument and modifies it, which differs from the standard signature.
// ReadByte reads a byte.
func (dec *BinaryDecoder) ReadByte(value *byte) error {
if _, err := io.ReadFull(dec.r, dec.bs[:1]); err != nil {
return BadDecodingError
}
*value = dec.bs[0]
return nil
}
Then the fix would be something along these lines?
// ReadByte reads a byte.
func (dec *BinaryDecoder) ReadByte() (byte, error) {
var b [1]byte
if _, err := io.ReadFull(dec.r, b[:]); err != nil {
return 0, err // Return zero value for byte and the error
}
return b[0], nil // Return the byte read and nil for error
}
@awcullen, what is your view on this? and did you transpile this from open62541 or...?
@elgohr Thanks so much for reporting this issue. When encoding/decoding a slice, the library calculated one address too many. Now all tests pass.
I would prefer to leave ReadByte and the other decoder signatures unchanged. I would rather not allocate new return values.
When running
go test -race ./...
the errorfatal error: checkptr: pointer arithmetic result points to invalid allocation
occurs. This is a typical error whenunsafe.Pointer
rules are not respected (https://pkg.go.dev/unsafe#Pointer).Running
go vet ./...
points into the direction ofua/binary_decoder.go:356:27: method ReadByte(value *byte) error should have signature ReadByte() (byte, error)