Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endian issues with iff importer. #481

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

MaddTheSane
Copy link
Contributor

Pull Request Type

  • GitHub Workflow changes
  • Documentation or Wiki changes
  • Build and Dependency changes
  • Runtime changes
    • Render changes
    • Audio changes
    • Input changes
    • Network changes
    • Other changes

Description

There were a couple of places that weren't byte-swapped on little-endian systems. And due to cf_ReadInt and cf_ReadShort automatically calling INTEL_INT which then byte-swaps the value on big-endian machines, the next calls to MOTOROLA_SHORT and MOTOROLA_INT don't swap the value because it's on a big-endian machine.

Checklist

  • I have tested my changes locally and verified that they work as intended.
  • I have documented any new or modified functionality.
  • I have reviewed the changes to ensure they do not introduce any unnecessary complexity or duplicate code.
  • I understand that by submitting this pull request, I am agreeing to license my contributions under the project's license.

Additional Comments

It should now work on big-endian machines.
@winterheart
Copy link
Collaborator

I'd recommend implement additional cf_ReadShortBE() and cf_ReadIntBE() or extend current cf_ReadShort() and cf_ReadInt() with optional parameter little_endian in CFILE module like this:

// Declaration in cfile.h
int32_t cf_ReadInt(CFILE *cfp, bool little_endian = true);

// Implementation in cfile.cpp
int32_t cf_ReadInt(CFILE *cfp, bool little_endian) {
  int32_t i;
  cf_ReadBytes((uint8_t *)&i, sizeof(i), cfp);
  return (little_endian ? INTEL_INT(i) : MOTOROLA_INT(i));
}

After that you can use it without additional conversion code in iff

@winterheart winterheart self-requested a review July 3, 2024 09:19
Copy link
Collaborator

@winterheart winterheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Linux, no regression found.

@winterheart winterheart merged commit 4c574bf into DescentDevelopers:main Jul 3, 2024
10 checks passed
@MaddTheSane MaddTheSane deleted the iffSafe branch July 5, 2024 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants