From 9e0cfdcda96c1d503232f71096566b46de424738 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 5 Aug 2021 03:18:28 +0000 Subject: [PATCH] Correctly handle null pointers returned from Rust representing None Fixes the SEGFAULT in #35. --- java_strings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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", -- 2.39.5