From: Matt Corallo Date: Thu, 5 Aug 2021 03:18:28 +0000 (+0000) Subject: Correctly handle null pointers returned from Rust representing None X-Git-Tag: v0.0.99.2~13 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=commitdiff_plain;h=9e0cfdcda96c1d503232f71096566b46de424738 Correctly handle null pointers returned from Rust representing None Fixes the SEGFAULT in #35. --- diff --git a/java_strings.py b/java_strings.py index f6bf763d..d4931cd9 100644 --- a/java_strings.py +++ b/java_strings.py @@ -106,7 +106,7 @@ import java.util.LinkedList; class CommonBase { long ptr; LinkedList ptrs_to = new LinkedList(); - protected CommonBase(long ptr) { this.ptr = ptr; } + protected CommonBase(long ptr) { assert ptr > 1024; this.ptr = ptr; } } """ @@ -1226,6 +1226,9 @@ import java.util.Arrays; else: out_java_struct += (info.arg_name) out_java_struct += (");\n") + if return_type_info.java_ty == "long" and return_type_info.java_hu_ty != "long": + out_java_struct += "\t\tif (ret < 1024) { return null; }\n" + if return_type_info.to_hu_conv is not None: if not takes_self: out_java_struct += ("\t\t" + return_type_info.to_hu_conv.replace("\n", "\n\t\t").replace("this",