Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Wrong ffi_type for unsigned numbers causes bugs on some platforms

Ouverte
#1,435 3 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
android, c, java
Domaine
devtools, mobile-dev

Piste de recherche

Commencez par l’exemple minimal reproductible lié dans le rapport, en vous concentrant sur IntegerType de JNA et sur l’argument UINT16 passé à la fonction native hello. Reproduisez la différence entre les builds Android optimisés et non optimisés, puis suivez la représentation FFI de unsigned short ; le travail est terminé lorsque hello renvoie true avec la valeur attendue sur les architectures concernées.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
Langage dominant
Java
Étoiles
8.9k
Forks
1.7k
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de java-native-access/jna

Toutes les issues de java-native-access/jna

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.