Correctly handle top-bit-set pointers, fixing Android 11
authorMatt Corallo <git@bluematt.me>
Sat, 9 Oct 2021 23:28:00 +0000 (23:28 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 10 Oct 2021 00:56:12 +0000 (00:56 +0000)
java_strings.py
typescript_strings.py

index d2054a172237019f84284beceab2b31834dca60e..1e7ba997083b055cbe04113be14ddb0851b6d90d 100644 (file)
@@ -115,7 +115,7 @@ import java.util.LinkedList;
 class CommonBase {
        long ptr;
        LinkedList<Object> ptrs_to = new LinkedList();
-       protected CommonBase(long ptr) { assert ptr > 1024; this.ptr = ptr; }
+       protected CommonBase(long ptr) { assert ptr < 0 || ptr > 1024; this.ptr = ptr; }
 }
 """
 
@@ -1258,7 +1258,7 @@ import javax.annotation.Nullable;
                     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"
+                out_java_struct += "\t\tif (ret >= 0 && ret < 1024) { return null; }\n"
 
             if return_type_info.to_hu_conv is not None:
                 if not takes_self:
index c097921f7d43de5ebc733be09392e1b24e19a6e4..84b27c5723a66521d7f737ac486313b1aac52cb2 100644 (file)
@@ -120,7 +120,7 @@ void *malloc(size_t size);
 void free(void *ptr);
 
 #define MALLOC(a, _) malloc(a)
-#define FREE(p) if ((long)(p) > 1024) { free(p); }
+#define FREE(p) if ((unsigned long)(p) > 1024) { free(p); }
 #define DO_ASSERT(a) (void)(a)
 #define CHECK(a)
 """
@@ -174,7 +174,7 @@ static void alloc_freed(void* ptr) {
        __real_free(it);
 }
 static void FREE(void* ptr) {
-       if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
+       if ((unsigned long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
        alloc_freed(ptr);
        __real_free(ptr);
 }