summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-06-17 21:51:16 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-06-17 21:51:16 -0400
commitf71ea8c456d30aee004e4e368ab8c89c74a2a5a2 (patch)
tree493e6bfc40ca86e254ef397cc056f1d8a2ac8cac
parent132cb9ec42cc4fb6c4a20c49422413ab0a62ef6e (diff)
Correctly handle 0-length byte arrays in IO.
-rw-r--r--proto/io.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/proto/io.go b/proto/io.go
index 3c0c5be..1f46503 100644
--- a/proto/io.go
+++ b/proto/io.go
@@ -48,9 +48,11 @@ func Write(fd io.Writer, data interface{}) {
case nslcdObject:
data.nslcdWrite(fd)
case []byte:
- _, err := fd.Write(data)
- if err != nil {
- panic(err)
+ if len(data) > 0 {
+ _, err := fd.Write(data)
+ if err != nil {
+ panic(err)
+ }
}
case int32:
err := binary.Write(fd, binary.BigEndian, data)
@@ -109,9 +111,11 @@ func Read(fd io.Reader, data interface{}) {
case nslcdObjectPtr:
data.nslcdRead(fd)
case *[]byte:
- _, err := fd.Read(*data)
- if err != nil {
- panic(err)
+ if len(*data) > 0 {
+ _, err := fd.Read(*data)
+ if err != nil {
+ panic(err)
+ }
}
case *int32:
err := binary.Read(fd, binary.BigEndian, data)