Skip to content

fix: resolve compiler warnings on macOS (clang) and Linux - #1140

Merged
dimitri merged 2 commits into
mainfrom
fix/compiler-warnings
Jul 10, 2026
Merged

fix: resolve compiler warnings on macOS (clang) and Linux#1140
dimitri merged 2 commits into
mainfrom
fix/compiler-warnings

Conversation

@dimitri

@dimitri dimitri commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Clang 15+ on macOS (Apple Silicon / Xcode 15) emits -Wdangling-assignment
for a pattern that appears throughout the Citus coordinator and demo-app
code:

paramValues[N] = intToString(expr).strValue;

intToString() returns an IntString struct by value; its embedded
char strValue[21] array lives in a stack temporary that is destroyed at
end of the full-expression, leaving paramValues[N] dangling before the
next pgsql_execute_with_params() call. The pointer happens to remain
valid until the next stack frame push on current compilers, but the pattern
is formally undefined and the warning is correct.

Fix: declare a named IntString variable so its lifetime extends
across the subsequent libpq call.

Changes

File Warning Fix
coordinator.c (12 sites) -Wdangling-assignment on intToString().strValue declare IntString variable before assigning to paramValues[]
demoapp.c (8 sites) same same
primary_standby.c -Wunused-but-set-variable — loop counter attempts never read replace for (int attempts = 0;; attempts++) with for (;;)
cli_formation.c -Wunused-but-set-variableerrors incremented in default: case but never checked add missing if (errors > 0) { commandline_help(); exit(); } guard (matches the pattern in the sibling keeper_cli_formation_drop_getopts; also closes a latent logic gap where unknown options were silently ignored)

Testing

make -C src/bin clean all produces zero warnings on macOS 15 (Apple
Silicon, clang 17) after this patch. No behaviour change — the
IntString struct is copied to the stack variable; the string content
and the pointer value are identical.

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).
@dimitri dimitri self-assigned this Jul 10, 2026
@dimitri dimitri added the bug Something isn't working label Jul 10, 2026
@dimitri
dimitri merged commit 6e3ba1d into main Jul 10, 2026
79 of 80 checks passed
@dimitri
dimitri deleted the fix/compiler-warnings branch July 10, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant