Skip to content

SIGSEGV when DEBUG is enabled for the volume routine (NATCRS references unassociated dummies VN, VM) #60

Description

@mihiarc

Bug: SIGSEGV when DEBUG is enabled for the volume routine (NATCRS)

Enabling the DEBUG keyword so that the volume routine is traced crashes FVS with a
segmentation fault during the run (exit 139). It reproduces with the repo's default
gfortran build (bin/makefile) for any variant and any stand that computes volume.
Normal (non-DEBUG) runs are unaffected.

Root cause. In vvolume/fvsvol.f, near the end of ENTRY NATCRS:

      IF(DEBUG)WRITE(JOSTND,*)'  IN FVSVOL D, VN, VM, VMAX, BBFV = ',
     &                            D, VN, VM, VMAX, BBFV

VN and VM are dummy arguments of ENTRY OCFVOL, not of ENTRY NATCRS. When
NATCRS is the active entry they are unassociated; the list-directed write then
dereferences a null pointer. The label and operands match the OCFVOL trace a few
lines down (where VN/VM are valid), so it appears to be a copy/paste into the
NATCRS fall-through path.

Backtrace (top frames):

get_float_string (libgfortran)   <- EXC_BAD_ACCESS, address 0x0
list_formatted_write_scalar
master.0.fvsvol_   fvsvol.f   (IF(DEBUG)WRITE in ENTRY NATCRS)
natcrs_           fvsvol.f
vols_  -> update_ -> gradd_ -> tregro_ -> fvs_

Reproduce: any stand with NUMCYCLE >= 1 plus a DEBUG keyword that turns
debugging on while volume is computed.

Fix: trace NATCRS's own assigned outputs (TCF,MCF,SCF) instead of the
unassociated VN,VM. PR attached. The change is confined to the IF(DEBUG) path and
does not alter computed model output (verified byte-identical before/after).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions