Fix off-by-one error converting strings

* The length returned by PyBytes_AsStringAndSize isn't the byte size
  including null terminator, but the number of bytes in the string.
This commit is contained in:
baldurk
2017-04-18 14:52:51 +01:00
parent 2a4596e06a
commit 1d1b7d8c55
+4 -4
View File
@@ -454,9 +454,9 @@ struct TypeConversion<rdctype::str, false>
if(ret == 0)
{
out.count = (int)size - 1;
out.elems = (char *)out.allocate(size);
memcpy(out.elems, buf, size - 1);
out.count = (int)size;
out.elems = (char *)out.allocate(size + 1);
memcpy(out.elems, buf, size);
out.elems[size] = 0;
Py_DecRef(bytes);
@@ -508,7 +508,7 @@ struct TypeConversion<QString, false>
if(ret == 0)
{
out = QString::fromUtf8(buf, (int)(size - 1));
out = QString::fromUtf8(buf, (int)size);
Py_DecRef(bytes);