Skip to content

fix(swift): unwrap baseAddress before memcpy in WriteBuffer.append(UnsafeRawBufferPointer) - #3762

Open
pcbeingused333 wants to merge 1 commit into
square:masterfrom
pcbeingused333:fix/swift-writebuffer-linux-nonnull
Open

pcbeingused333 wants to merge 1 commit into
square:masterfrom
pcbeingused333:fix/swift-writebuffer-linux-nonnull

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #3757

Cause: WriteBuffer.append(_ value: UnsafeRawBufferPointer) passes value.baseAddress (an UnsafeRawPointer?) straight to memcpy. On Darwin the parameter is nullable, but glibc declares it nonnull, so the Swift runtime does not compile on Linux (Swift 6.2, Ubuntu 24.04).

Fix: bind baseAddress in the existing guard (empty buffers still return early) and pass the unwrapped pointer.

Test: added WriteBufferTests.testAppendRawBufferPointer (non-empty and empty/nil-base buffers). swift build --target Wire in swift:6.2 fails before the change with the error from the issue and succeeds after. The XCTest target itself does not build on Linux in this setup, so the new test was not run.


This PR was prepared with the assistance of an AI coding agent (Claude) and submitted by a human contributor who is responsible for it.

…safeRawBufferPointer)

On Linux, glibc declares memcpy's source parameter as nonnull, so passing the
optional UnsafeRawBufferPointer.baseAddress fails to compile.

@oldergod oldergod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please sign the Square Contributor License Agreement before this merges: https://docs.google.com/forms/d/e/1FAIpQLSeRVQ35-gq2vdSxD1kdh7CJwRdjmUA0EZ9gRXaWYoUeKPZEQQ/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1. I could not find your GitHub user name on the list of signers.

@pcbeingused333

Copy link
Copy Markdown
Author

Thanks for approving this! Whenever you have a moment, it should be ready to merge (CI is green). Happy to rebase or adjust anything if needed.

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.

Swift runtime doesn’t compile on Linux: WriteBuffer.append(_:) passes an optional pointer to memcpy

2 participants