fix: resolve compiler warnings on macOS (clang) and Linux - #1140
Merged
Conversation
Clang on macOS (Apple Silicon, Xcode 15+) emits -Wdangling-assignment
for patterns like:
paramValues[N] = intToString(expr).strValue;
intToString() returns an IntString struct by value; its embedded
strValue[] char array is in a stack temporary that is destroyed at end
of expression, leaving paramValues[N] dangling before the next
pgsql_execute_with_params() call.
Fix: declare a named IntString variable so its lifetime covers the
subsequent call. The compiler warning fires in C99/C11 mode on clang
15+ and in practice the pointer is stable until the stack frame is
reused, but the pattern is formally undefined and must be corrected.
Additional fixes:
- primary_standby.c: remove unused loop counter in crash-recovery
wait loop (variable 'attempts' set but not used).
- cli_formation.c: add missing errors > 0 check in
keeper_cli_formation_create_getopts() matching the pattern in
keeper_cli_formation_drop_getopts(); the variable was correctly
incremented in the default: case but the exit guard was missing
(variable 'errors' set but not used, and a latent logic gap).
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.
Summary
Clang 15+ on macOS (Apple Silicon / Xcode 15) emits
-Wdangling-assignmentfor a pattern that appears throughout the Citus coordinator and demo-app
code:
intToString()returns anIntStringstruct by value; its embeddedchar strValue[21]array lives in a stack temporary that is destroyed atend of the full-expression, leaving
paramValues[N]dangling before thenext
pgsql_execute_with_params()call. The pointer happens to remainvalid until the next stack frame push on current compilers, but the pattern
is formally undefined and the warning is correct.
Fix: declare a named
IntStringvariable so its lifetime extendsacross the subsequent libpq call.
Changes
coordinator.c(12 sites)-Wdangling-assignmentonintToString().strValueIntStringvariable before assigning toparamValues[]demoapp.c(8 sites)primary_standby.c-Wunused-but-set-variable— loop counterattemptsnever readfor (int attempts = 0;; attempts++)withfor (;;)cli_formation.c-Wunused-but-set-variable—errorsincremented indefault:case but never checkedif (errors > 0) { commandline_help(); exit(); }guard (matches the pattern in the siblingkeeper_cli_formation_drop_getopts; also closes a latent logic gap where unknown options were silently ignored)Testing
make -C src/bin clean allproduces zero warnings on macOS 15 (AppleSilicon, clang 17) after this patch. No behaviour change — the
IntStringstruct is copied to the stack variable; the string contentand the pointer value are identical.