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 type incompatibility in htole64 and htole32 with older GCC versions #355

Merged
merged 1 commit into from
Mar 16, 2025

Conversation

pfichtner
Copy link
Contributor

Problem

Older versions of GCC (e.g., 4.6.4) report a type incompatibility error due to the way &out.bytes is passed to STORE64L and STORE32L.

src/compat.c: In function 'htole64':
src/compat.c:291:2: error: incompatible types when assigning to type 'uint8_t[8]' from type 'unsigned char'

out.bytes is an array (uint8_t[8] for htole64, uint8_t[4] for htole32).
&out.bytes produces uint8_t (*)[8] (uint8_t (*)[4] for htole32), which does not match the expected uint8_t* parameter in STORE64L and STORE32L.
Newer compilers (e.g., GCC 4.8.5+) are more lenient, but older versions enforce strict type checking, leading to compilation errors.

Solution

Instead of passing &out.bytes, we pass out.bytes directly. This ensures proper type decay from an array to a pointer (uint8_t*), making the code compatible with both older and newer GCC versions.

Changes

Before:

STORE64L(inp, &out.bytes);
STORE32L(inp, &out.bytes);

After:

STORE64L(inp, out.bytes);
STORE32L(inp, out.bytes);

This change resolves the compilation issue while maintaining functional correctness.

@mkj
Copy link
Owner

mkj commented Mar 16, 2025

Thanks

@mkj mkj merged commit bd12a86 into mkj:master Mar 16, 2025
18 checks passed
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