Repository navigation
Fix Windows/MinGW build: missing err.h, uninitialized pointer in stdlib.c - #29
Open
doomfrawen wants to merge 2 commits into
Open
doomfrawen wants to merge 2 commits into
doomfrawen wants to merge 2 commits into
Conversation
…ib.c - src/nfc-utils.h/.c and src/windows.h include <err.h>, a BSD/glibc-only header not shipped by MinGW-w64, so the GNU-toolchain build (autoreconf + gcc, as opposed to the VS2019/clang-cl path this repo also supports) fails with 'err.h: No such file or directory'. windows.h doesn't call anything from it, so that include is simply dropped. nfc-utils.h's DBG/WARN/ERR macros do use warnx(), so on _WIN32 this adds a small static inline warnx() shim instead of the header, and drops the redundant second #include <err.h> in nfc-utils.c. - src/stdlib.c's setenv()/unsetenv() declare 'char *str[32]' (an array of 32 uninitialized pointers) and then do strcpy(*str, name) etc, which dereferences the first (uninitialized/garbage) pointer in that array and writes through it - undefined behavior, not just a compile-time type mismatch. Changed to 'char str[32]' (an actual 32-byte buffer) and dropped the erroneous dereferences.
Apply the _putenv_s approach discussed in nfc-tools/libnfc#765 and maksimtech/libnfc#2 to the same compatibility helpers here. Return success when overwrite=0 preserves an existing value and reject invalid arguments before calling the CRT. Add hardware-free Windows regression checks for MinGW64 and UCRT64. Assisted-by: Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into missing
err.hsupport and invalid writes in the Windows environment helpers while building for native Windows with MSYS2 MinGW64.err.hincludes and added a Windowswarnx()shim for the diagnostic macros.char *str[32]implementation ofsetenv()andunsetenv()with_putenv_s, removing the fixed-size intermediate buffer as well. An existing variable withoverwrite=0now returns success without changing its value. I also added checks for invalid names and null values before calling the CRT, while keeping the existing voidunsetenv()signature and Windows empty-value removal behavior.For the environment helpers, I followed the feedback on nfc-tools/libnfc#765 and the approach in maksimtech/libnfc#2.
Validation at
25b312a:-Wall -Wextra -Werror.git diff --check, which passed.The tests I've added cover the Windows environment helpers, not a full application build. I haven't tested NFC hardware or the VS/clang-cl build for this update. The upstream workflows still need maintainer approval.