From 0ae938000dca0e8e10b8d7c184a942055e0edd28 Mon Sep 17 00:00:00 2001 From: Christopher Schmitt Date: Mon, 22 Jul 2019 13:18:28 -0600 Subject: [PATCH] Use GoStringN inside _AsString functions for bytes as they may contain NULLs --- byte_array.go | 2 +- bytes.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/byte_array.go b/byte_array.go index a027f95..c52d2d6 100644 --- a/byte_array.go +++ b/byte_array.go @@ -52,7 +52,7 @@ func PyByteArray_Size(o *PyObject) int { //PyByteArray_AsString : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString func PyByteArray_AsString(o *PyObject) string { - return C.GoString(C.PyByteArray_AsString(toc(o))) + return C.GoStringN(C.PyByteArray_AsString(toc(o)), C.int(C.PyByteArray_Size(toc(o)))) } //PyByteArray_Resize : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Resize diff --git a/bytes.go b/bytes.go index 0e91377..1ed45d2 100644 --- a/bytes.go +++ b/bytes.go @@ -47,7 +47,7 @@ func PyBytes_Size(o *PyObject) int { //PyBytes_AsString : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString func PyBytes_AsString(o *PyObject) string { - return C.GoString(C.PyBytes_AsString(toc(o))) + return C.GoStringN(C.PyBytes_AsString(toc(o)), C.int(C.PyBytes_Size(toc(o)))) } //PyBytes_Concat : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Concat