Skip to content

Commit

Permalink
#411 add len check for empty slices
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeraaperera committed May 13, 2022
1 parent 3487e8a commit d5d10af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions geom/wkb_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@ func (m *wkbMarshaler) writeSequence(seq Sequence) {
// floatsAsBytes reinterprets the floats slice as a bytes slice in a similar
// manner to reinterpret_cast in C++.
func floatsAsBytes(floats []float64) []byte {
if len(floats) == 0 {
return nil
}
return unsafe.Slice((*byte)(unsafe.Pointer(&floats[0])), 8*len(floats))
}
3 changes: 3 additions & 0 deletions geom/wkb_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (p *wkbParser) parseLineString(ctype CoordinatesType) (LineString, error) {
// bytesAsFloats reinterprets the bytes slice as a float64 slice in a similar
// manner to reinterpret_cast in C++.
func bytesAsFloats(byts []byte) []float64 {
if len(byts) == 0 {
return nil
}
return unsafe.Slice((*float64)(unsafe.Pointer(&byts[0])), len(byts)/8)
}

Expand Down

0 comments on commit d5d10af

Please sign in to comment.