Skip to content

UCS-2 Strings test (nan/test/js/strings.js) fails on big-endian systems #481

Closed

Description

@exinfinitum

Running the strings.js test on a big-endian system will cause a failure in the UCS-2 test case. This is caused by the fact that the encoding function is passed the string "h\0e\0l\0l\0o\0" (see nan/test/cpp/strings.cpp, line 29), with null characters following the ASCII characters.

Little endian systems will process the characters properly (e.g. "h\0" -> 0068 -> h), however big endian systems will require that the null characters be placed in front of the letters (the 0068 example will be read as "6800", which does not map to "h" in UCS-2).

Suggested fix: Use macros to check endianness of compiling machine, and flip the bytes if necessary.

Activity

  1. kkoopa commented on Oct 5, 2015

    @kkoopa
    Collaborator

    Ah, good idea, but it will be a blind fix, as we (obviously) have no big-endian systems to test on (because big-endian is unnatural...). I'll gladly merge a PR that keeps our test suite passing and take your word that it works on your end.

  2. exinfinitum commented on Oct 6, 2015

    @exinfinitum
    Author

    Upon further investigation, I have determined that this bug arises as a result of a change in the encode function in Node.js between versions v0.12 and v4.x. The encode function for UCS-2 in v0.12 reverses bytes if the system is big-endian, but in v4.x this check and reverse has been added to the string write function and removed from encode. Running nan test on v0.12 on a big-endian system results in no issues.

    As a result, this bug is an issue with node, and so isn't a nan issue.

    Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions