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

FileIO write( int, int ) in binary mode potentially incorrect #325

Open
gewang opened this issue Jun 2, 2023 · 0 comments
Open

FileIO write( int, int ) in binary mode potentially incorrect #325

gewang opened this issue Jun 2, 2023 · 0 comments

Comments

@gewang
Copy link
Member

gewang commented Jun 2, 2023

(binary mode only) presently Chuck_IO_File::write( t_CKINT val, t_CKINT flags ) simply writes starting at the pointer address of val and does not take into account size of architecture (64 vs 32 bit) nor endianness:

else if (m_flags & TYPE_BINARY) {
        int nBytes = 4;
        if(flags & INT8) nBytes = 1;
        else if(flags & INT16) nBytes = 2;
        else if(flags & INT32) nBytes = 4;
        m_io.write( (char *)&val, nBytes );
    }

possibly the values written should be copied into appropriately sized variables, and possibly byte-swapped (this need to also take into account how FileIO binary mode read expects endianness in ints), before written to file.

cc @nshaheed @spencersalazar

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

No branches or pull requests

1 participant