From 07acc6c794da71c4c62932b4dc262d9c712f4b98 Mon Sep 17 00:00:00 2001 From: Takahiro Ueda Date: Tue, 27 Oct 2026 15:27:42 +0900 Subject: [PATCH] fix: prevent a possible segfault at EndModel Fix a typo in the code that shifts entries in the coupling constant list in CoEndModel(), which led to a segfault. Close #925. --- check/fixes.frm | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ sources/model.c | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/check/fixes.frm b/check/fixes.frm index 94c7198cf..96783c8b1 100644 --- a/check/fixes.frm +++ b/check/fixes.frm @@ -5245,6 +5245,83 @@ Print; assert succeeded? assert result("test") =~ expr("4+4*x") *--#] Issue882_6 : +*--#[ Issue925_1 : +* Insert an item into the list of coupling constants. +S g2,g1; * order-dependent segfault +Auto V p,q; +Model mod; + Particle phi1 +1; + Particle phi2 +1; + Vertex phi1 phi1 phi1 : g1; + Vertex phi2 phi2 phi2 : g2; +EndModel; +L F1 = diagrams_(mod,{phi1,phi1},{},{q1,q2},{p1,p2},1,`NoSnail_'); +L F2 = diagrams_(mod,{phi2,phi2},{},{q1,q2},{p1,p2},1,`NoSnail_'); +P +ss; +.end +assert succeeded? +assert result("F1") =~ expr(" + + + 1/2 + *topo_(1) + *node_(1,1,phi1(-q1)) + *node_(2,1,phi1(-q2)) + *node_(3,g1,phi1(q1),phi1(-p1),phi1(-p2)) + *node_(4,g1,phi1(q2),phi1(p1),phi1(p2)) +") +assert result("F2") =~ expr(" + + + 1/2 + *topo_(1) + *node_(1,1,phi2(-q1)) + *node_(2,1,phi2(-q2)) + *node_(3,g2,phi2(q1),phi2(-p1),phi2(-p2)) + *node_(4,g2,phi2(q2),phi2(p1),phi2(p2)) +") +*--#] Issue925_1 : +*--#[ Issue925_2 : +* Extend the list of coupling constants. +#define N "15" * N >= 12 +Auto V p,q; +Model mod; + #do i=1,`N' + Particle phi`i' +1; + #enddo + #do i=1,`N' + Vertex phi`i' phi`i' phi`i' : g`i'; + #enddo +EndModel; +L n = `N'; +L F1 = diagrams_(mod,{phi1,phi1},{},{q1,q2},{p1,p2},1,`NoSnail_'); +L F`N' = diagrams_(mod,{phi`N',phi`N'},{},{q1,q2},{p1,p2},1,`NoSnail_'); +P +ss; +.end +assert succeeded? +assert result("F1") =~ expr(" + + + 1/2 + *topo_(1) + *node_(1,1,phi1(-q1)) + *node_(2,1,phi1(-q2)) + *node_(3,g1,phi1(q1),phi1(-p1),phi1(-p2)) + *node_(4,g1,phi1(q2),phi1(p1),phi1(p2)) +") +n = result("n").to_i +assert result("F#{n}") =~ expr(" + + + 1/2 + *topo_(1) + *node_(1,1,phi#{n}(-q1)) + *node_(2,1,phi#{n}(-q2)) + *node_(3,g#{n},phi#{n}(q1),phi#{n}(-p1),phi#{n}(-p2)) + *node_(4,g#{n},phi#{n}(q2),phi#{n}(p1),phi#{n}(p2)) +") +*--#] Issue925_2 : +*--#[ Issue925_e1 : +EndModel; +.end +assert compile_error?("EndModel statement without matching Model statement") +*--#] Issue925_e1 : *--#[ PullReq535 : * This test requires more than the specified 50K workspace. #:maxtermsize 200 diff --git a/sources/model.c b/sources/model.c index d64e64de2..6a3fc677a 100644 --- a/sources/model.c +++ b/sources/model.c @@ -449,7 +449,7 @@ int CoEndModel(UBYTE *s) for ( k = 0; k < m->ncouplings; k++ ) { if ( sym == m->couplings[k] ) break; if ( sym < m->couplings[k] ) { - for ( kk = m->ncouplings; kk > k; k-- ) + for ( kk = m->ncouplings; kk > k; kk-- ) m->couplings[kk] = m->couplings[kk-1]; m->couplings[k] = sym; m->ncouplings++;