Skip to content

fix: Avoid implicit 64-to-32-bit conversions on 32-bit platforms - #983

Open
ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/797-shorten-64-to-32
Open

ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/797-shorten-64-to-32

Conversation

@ump45nose

Copy link
Copy Markdown

Closes #797.

Building nanoarrow with -Wconversion on a 32-bit target (the armv7 Android build in the vcpkg CI from the issue) fails with -Wshorten-64-to-32 errors, because a number of int64_t sizes are passed straight to functions that take size_t: memcpy/memset/memmove, snprintf, malloc/realloc, fread/fwrite, strncmp, and the flatcc builder/vector helpers.

This adds explicit (size_t) casts at those call sites in common/, device/device.c and ipc/. There's no behaviour change on 64-bit platforms. In ArrowArrayViewCompareBuffer() the size_bytes > 0 check stays on the signed value and only the length handed to memcmp() is converted, so the stringified comparison message the tests check doesn't change.

Testing

  • clang -m32 -std=gnu99 -fsyntax-only -Wall -Wextra -Wpedantic -Wconversion -Wno-sign-conversion (clang 19, i386) over src/nanoarrow/common/*.c, device/device.c and ipc/{codecs,decoder,encoder,reader,writer}.c: 40 distinct -Wshorten-64-to-32 warning locations on main, none with this change. I don't have the Android NDK setup locally, so this is a 32-bit x86 stand-in for the armv7 build.
  • Native 64-bit Debug build with NANOARROW_BUILD_TESTS=ON NANOARROW_IPC=ON NANOARROW_DEVICE=ON: ctest 422/422 passed.
  • clang-format 16.0.6 (the pre-commit version) applied.

This PR was prepared with AI assistance; I reviewed the changes and ran the checks above.

Building with -Wconversion on 32-bit targets (e.g. armv7 Android in the
vcpkg CI) fails because several int64_t values are passed to functions
that take size_t (memcpy, memset, snprintf, malloc, fread and flatcc
builder helpers). Cast these explicitly.

Closes apache#797.

This branch has not been deployed

No deployments
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.

Fix compiler warnings on Anroid/ARM NEON

1 participant