Skip to content

chem: add scalar guards for p_hcl and p_ch3cl in add_anthropogenics t… - #2387

Open
AlphaBetaGammaChi wants to merge 3 commits into
wrf-model:release-v4.8.1from
AlphaBetaGammaChi:fix-cri-anthropogenic-emissions-segfault
Open

chem: add scalar guards for p_hcl and p_ch3cl in add_anthropogenics t…#2387
AlphaBetaGammaChi wants to merge 3 commits into
wrf-model:release-v4.8.1from
AlphaBetaGammaChi:fix-cri-anthropogenic-emissions-segfault

Conversation

@AlphaBetaGammaChi

Copy link
Copy Markdown

Fixes a runtime SIGSEGV crash during emissions_driver when running chemical mechanisms that do not include anthropogenic chlorine (such as CRI-MECH with emiss_opt = 19 or emiss_opt = 20).

Cause
In chem/module_emissions_anthropogenics.F, assignments for p_hcl and p_ch3cl were placed in the generic anthropogenic emissions loop without param_first_scalar bounds checks.
For mechanisms where e_hcl and e_ch3cl are not present in the package, referencing chem(..., p_hcl) and emis_ant(..., p_e_hcl) causes an invalid memory reference and crashes on timestep 1:

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace:
__module_emissions_driver_MOD_emissions_driver
chem_driver_
solve_interface_

@AlphaBetaGammaChi
AlphaBetaGammaChi requested a review from a team as a code owner August 28, 2026 15:07
@weiwangncar

Copy link
Copy Markdown
Collaborator

The regression results:

Test Type              | Expected  | Received |  Failed
= = = = = = = = = = = = = = = = = = = = = = = =  = = = =
Number of Tests        : 23           24
Number of Builds       : 60           57
Number of Simulations  : 158           150        0
Number of Comparisons  : 95           86        0

Failed Simulations are: 
None
Which comparisons are not bit-for-bit: 
None

AlphaBetaGammaChi and others added 2 commits August 30, 2026 10:40
…from uninitialized loop indices

In WRF 4.8, area=(dx/mapfac_mx(i,j))*(dy/mapfac_my(i,j)) was placed at
subroutine entry before loop indices i and j are initialized. On modern
compilers (e.g. GCC 13 on aarch64/x86_64 with -O3), this causes an immediate
SIGSEGV out-of-bounds memory access. Restores the safe area=dx*dx calculation.
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.

2 participants