Skip to content

Commit d3d33c6

Browse files
author
Thorsten Riess
committed
Changed docstring, length to uint64 + range check
1 parent 0f12455 commit d3d33c6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sequence.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ func PyByteArray_AsString(self *PyObject) string {
8989
return C.GoString(c_str)
9090
}
9191

92-
// Return the contents of bytearray as []bytes
92+
// PyByteArray_AsBytes returns the contents of bytearray as []bytes
9393
func PyByteArray_AsBytes(self *PyObject) []byte {
9494
length := C._gopy_PyByteArray_GET_SIZE(topy(self))
9595
c_str := C.PyByteArray_AsString(topy(self))
9696
return C.GoBytes(unsafe.Pointer(c_str),C.int(length))
9797
}
9898

99-
// Return the contents of bytearray as []bytes, size length
100-
func PyByteArray_AsBytesN(self *PyObject, length int) []byte {
99+
// PyByteArray_AsBytesN returns the contents of bytearray as []bytes, size length
100+
func PyByteArray_AsBytesN(self *PyObject, length uint64) []byte {
101+
blength := uint64(C._gopy_PyByteArray_GET_SIZE(topy(self)))
102+
if blength < length {
103+
panic("bytearray length out of range")
104+
}
101105
c_str := C.PyByteArray_AsString(topy(self))
102106
return C.GoBytes(unsafe.Pointer(c_str),C.int(length))
103107
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy