Skip to content

keypair.cpp: include <malloc.h> for alloca on Windows - #459

Open
Mikke404 wants to merge 1 commit into
ValveSoftware:masterfrom
Mikke404:fix-keypair-alloca-msvc
Open

Mikke404 wants to merge 1 commit into
ValveSoftware:masterfrom
Mikke404:fix-keypair-alloca-msvc

Conversation

@Mikke404

Copy link
Copy Markdown

src/common/keypair.cpp calls alloca (four places) but doesn't include <malloc.h>, where MSVC declares it.

It compiles today only because MSVC's <exception> header includes <malloc.h>, and only when _HAS_EXCEPTIONS is 1. With exceptions fully disabled (/EHs-c- /D_HAS_EXCEPTIONS=0, e.g. a vcpkg triplet that sets this for every port) the build fails:

src\common\keypair.cpp(288): error C3861: 'alloca': identifier not found

Seen with MSVC 14.41 (VS 2022), GNS 1.6.0 from vcpkg, USE_CRYPTO=OpenSSL. Removing only /D_HAS_EXCEPTIONS=0 from the same compile command makes it compile; with this include it compiles either way. Other platforms are unaffected (guarded by _WIN32).

We carry this as a vcpkg overlay patch for now and have verified it in CI with MSVC (Debug and Release) and the loopback connection test.

🤖 Generated with Claude Code

keypair.cpp calls alloca without including <malloc.h>, where MSVC declares
it. It compiled only because MSVC's <exception> includes <malloc.h>, and
only when _HAS_EXCEPTIONS is 1. With exceptions fully disabled
(/EHs-c- /D_HAS_EXCEPTIONS=0) the build fails with
error C3861: 'alloca': identifier not found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant