Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bech32.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int wally_addr_segwit_from_bytes(const unsigned char *bytes, size_t bytes_len,
const char *addr_family, uint32_t flags,
char **output)
{
char result[90];
char result[90 + 1]; /* Max encoded length plus NUL */
size_t push_size;
int ret;
size_t witver;
Expand Down
8 changes: 5 additions & 3 deletions src/swig_python/swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ del swig_import_helper
#include "../internal.h"

#undef malloc
#undef calloc
#undef free
#define malloc(size) wally_malloc(size)
#define calloc(n, size) wally_calloc((n) * (size))
#define free(ptr) wally_free(ptr)

static int check_result(int result)
Expand Down Expand Up @@ -182,7 +184,7 @@ static void destroy_words(PyObject *obj) { (void)obj; }
}
%typemap(argout) size_t* written {
Py_DecRef($result);
$result = PyInt_FromSize_t(*$1);
$result = PyLong_FromSize_t(*$1);
}

%typemap(in, numinputs=0) uint32_t *value_out (uint32_t val) {
Expand All @@ -209,7 +211,7 @@ static void destroy_words(PyObject *obj) { (void)obj; }
%typemap(argout) char** {
if (*$1 != NULL) {
Py_DecRef($result);
$result = PyString_FromString(*$1);
$result = PyUnicode_FromString(*$1);
wally_free_string(*$1);
}
}
Expand All @@ -228,7 +230,7 @@ static void destroy_words(PyObject *obj) { (void)obj; }
Py_DecRef($result);
$result = PyList_New($2);
for (i = 0; i < $2; i++) {
PyObject *s = PyString_FromString($1[i]);
PyObject *s = PyUnicode_FromString($1[i]);
PyList_SetItem($result, i, s);
wally_free_string($1[i]);
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/test_bech32.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
'tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c':
['tb', 1, '5120000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433'],
'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0':
['bc', 1, '512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798']
['bc', 1, '512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'],
# Maximum length (90 character) address: 30 character hrp, 32 byte v0 program
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6nf3d':
['a' * 30, 0, '0020' + '00' * 32],
}

invalid_cases = [
Expand Down
Loading