Skip to content

Fix Standard-mode parameter checks and latent bugs in the C generator - #62

Open
aoymt wants to merge 6 commits into
developfrom
fix/c-standard-mode-checks
Open

Fix Standard-mode parameter checks and latent bugs in the C generator#62
aoymt wants to merge 6 commits into
developfrom
fix/c-standard-mode-checks

Conversation

@aoymt

@aoymt aoymt commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This PR collects six small fixes to the Standard-mode C generator found
during a systematic review (cross-checked against the Python port). All
fixes are confirmed against the full base-mode integration suite
(94/94 tests pass before and after; none of the changes affect the
generated definition files).

Fixes

  1. TriangularLattice: t'' unused-parameter check inspected the wrong
    variable
    (e52627d)
    The spin-model branch checked StdI->tp (already checked as t' on
    the previous line) instead of StdI->tpp, so a specified t'' was
    silently ignored.
    Behavior change: spin-model inputs that specify t'' were
    silently accepted before and now abort with the standard
    unused-parameter error.

  2. Kagome: duplicated, mislabeled check (aca0821)
    StdI->t was checked twice in the spin-model branch, the second time
    under the wrong label "t0" (the real t0 is checked on the next
    line). The redundant mislabeled line is removed; specifying t still
    aborts, now with a single correctly-labeled message.

  3. Tetragonal / Honeycomb: re-print of the consumed V' fallback
    (e6d897d)
    V' only serves as the fallback input for V0'/V1'(/V2') via
    StdFace_InputCoulombV, but these two lattices then re-ran
    StdFace_PrintVal_d on it, logging it as if it were an independent
    parameter. stdout logging is the only observable change; no other
    lattice does this.

  4. Wannier90: braceless ifs in the cutoff_*Vec parameter loops
    (74bd911)
    The if guarded only the sprintf, so with box[i][j] unset,
    StdFace_PrintVal_d would run with a stale label and a garbage
    default (NaN_i * 0.5). Unreachable in practice because
    StdFace_InitSite fills box first — output is unchanged — but the
    braces make the intended conditional explicit.

  5. Wannier90: tUJ/tUJindx initialised to NULL (5645bb4)
    Prevents freeing uninitialised pointers on early-exit paths.

  6. Wannier90: error out when _ur.dat is missing for the spin model
    (115e605)
    The superexchange J = 4t²/U needs the on-site U values; a missing
    _ur.dat previously crashed later instead of giving a clear error.

Not included

A seventh finding — the OmegaIm default is computed as
0.01 * (int)StdI->LargeValue (StdFace_main.c), truncating the
fractional part of LargeValue — changes a physics-facing default and
is proposed separately as its own PR (fix/omegaim-default) so it can
be discussed and merged independently.

Notes for reviewers

  • The base-mode integration suite on this branch passes 94/94 both
    before and after the fixes; none of the reference files change.
  • The pytest (3.10) CI job may fail on this branch for an unrelated,
    pre-existing reason (tomllib is Python 3.11+ stdlib; fixed on the
    Python development line). This PR intentionally touches only src/.

🤖 Generated with Claude Code

aoymt and others added 6 commits July 20, 2026 08:25
…values

When _ur.dat or _jr.dat are absent, read_W90 returns early without
setting tUJ[itUJ] or tUJindx[itUJ].  The subsequent cleanup code
calls free() on these uninitialised pointers, which is undefined
behaviour and causes SEGV on Linux/glibc when the heap has been
previously used.

Initialise all three elements to NULL immediately after malloc so
that free(NULL) is called instead, which is safe per the C standard.

Diagnosed with valgrind: 4x "Conditional jump or move depends on
uninitialised value(s)" in free() called from StdFace_Wannier90.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without _ur.dat (NtUJ[1]==0), Uspin[] is malloc'd but never initialised.
The superexchange formula J = 4t²/U then reads garbage values, producing
non-reproducible output (inf or random J) and potential SEGV.

Add an explicit check before Uspin is used: if _ur.dat is absent, print
a clear error message and exit rather than proceeding with uninitialised
memory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tice

In the spin-model branch the unused-parameter check for t'' inspected
StdI->tp (already checked as t' on the previous line), so a specified
t'' was silently ignored instead of being rejected. Check StdI->tpp.

Note: inputs that previously specified t'' with a spin model were
silently accepted; they now abort with the standard unused-parameter
error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The spin-model branch checked StdI->t twice: once correctly labeled
"t" and once mislabeled "t0" (the real t0 is checked on the next
line). Remove the redundant mislabeled line; specifying t in a spin
model still aborts, now with a single correctly-labeled error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ycomb

V' only acts as the fallback input for V0'/V1'(/V2') via
StdFace_InputCoulombV, but Tetragonal and Honeycomb then re-ran
StdFace_PrintVal_d on it, logging it as if it were an independent
parameter (and resetting the consumed variable to 0). No other lattice
does this and nothing reads Vp afterwards; stdout logging is the only
observable change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The braceless ifs guarded only the sprintf, so when box[i][j] were
still unset StdFace_PrintVal_d would run unconditionally with a stale
label and a garbage default (NaN_i * 0.5). Unreachable in practice
because StdFace_InitSite fills box first, so output is unchanged; the
braces make the intended conditional explicit (and normalise a stray
double space in the JVec line).

Co-Authored-By: Claude Fable 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