Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4075067

byte array values incorrect with JDK compiled with some compilers

XMLWordPrintable

    • 1.2beta3
    • sparc
    • solaris_2.5.1
    • Not verified

      Versions of the JDK that are compiled with a C compiler (such as GCC) that treat chars as unsigned by default cause Java programs to interpret the value of an element in a byte array incorrectly. For example, the following code snippet will take the
      FAIL path:

          byte[] bytearray = new byte[100];
          bytearray[50] = (byte)222;
          if (bytearray[50] == (byte)222)
              // PASS
          else
              // FAIL

      At first glance it appears that modifying:

          typedef struct {
              char body[1];
          } ArrayOfByte;
          typedef ArrayOfByte ClassArrayOfByte;
          HandleTo(ArrayOfByte);

      in src/share/java/include/oobj.h to be:

          typedef struct {
              signed char body[1];
          } ArrayOfByte;
          typedef ArrayOfByte ClassArrayOfByte;
          HandleTo(ArrayOfByte);

      by adding the "signed" keyword should fix this problem.

            sliangsunw Sheng Liang (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: