Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Wrong ffi_type for unsigned numbers causes bugs on some platforms

Đang mở
#1,435 3 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
android, c, java
Lĩnh vực
devtools, mobile-dev

Hướng nghiên cứu

Bắt đầu với ví dụ tối thiểu có thể tái hiện được được liên kết trong báo cáo, tập trung vào IntegerType của JNA và đối số UINT16 được truyền vào hàm native hello. Tái hiện sự khác biệt giữa các bản build Android được tối ưu hóa và không được tối ưu hóa, sau đó theo dõi biểu diễn FFI của unsigned short; hoàn tất khi hello trả về true với giá trị mong đợi trên các kiến trúc bị ảnh hưởng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Provide complete information about the problem
  1. Version of JNA and related jars
    5.11.0@aar
  2. Version and vendor of the java virtual machine
    ART @ Android 11
  3. Operating system
    Android 11
  4. System architecture (CPU type, bitness of the JVM)
    arm64-v8a, x86_64, possibly more
    Output of clang --version:
    Compiler Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn).
  5. Complete description of the problem
    Function argument of type unsigned short passed by JNA to native code does not behave correctly when the code is compiled with optimizations enabled. The is caused by the fact that LLVM is counting on the argument being stored in straight format (as it should be) instead of two's complement.
  6. Steps to reproduce
    Minimal reproducible example available here.
    The hello function in the following code should return true, but returns false.
const unsigned short CONSTANT = 0x8810u;

bool hello(unsigned short argument) {
    __android_log_print(ANDROID_LOG_WARN, TAG, "argument value as %%#010x=%#010x %%d=%d, as %%u=%u, as %%hu=%hu", argument, argument, argument, argument);
    __android_log_print(ANDROID_LOG_WARN, TAG, "CONSTANT value as %%#010x=%#010x %%d=%d, as %%u=%u, as %%hu=%hu", CONSTANT, CONSTANT, CONSTANT, CONSTANT);
    switch (argument) {
        case CONSTANT:
            return true;
        default:
            return false;
    }
}
    private void logValueFromJna() {
        boolean on = lib.hello(new UINT16(0x8810));
        Log.w("JNA-BUG", "hello returned correct value? " + on);
    }

    public static class UINT16 extends IntegerType {

        @SuppressWarnings("unused")
        public UINT16() {
            this(0);
        }

        public UINT16(int value) {
            super(2, value, true);
        }
    }

    interface TestLibrary extends Library {
        boolean hello(UINT16 argument);
    }

Log output with optimizations disabled:

W/JNA-BUG-NATIVE: argument value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG-NATIVE: CONSTANT value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG: hello returned correct value? true

Log output with optimizations enabled:

W/JNA-BUG-NATIVE: argument value as %#010x=0xffff8810 %d=-30704, as %u=4294936592, as %hu=34832
W/JNA-BUG-NATIVE: CONSTANT value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG: hello returned correct value? false
Ngôn ngữ chính
Java
Star
8.9k
Fork
1.7k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của java-native-access/jna

Tất cả issue của java-native-access/jna

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.