Skip to content

Commit 3013645

Browse files
committed
Merge branch 'main' into iterated-filtering
2 parents d5cffa0 + 23e03f8 commit 3013645

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: SimInf
22
Title: A Framework for Data-Driven Stochastic Disease Spread Simulations
3-
Version: 9.8.1.9000
3+
Version: 10.1.0.9000
44
Authors@R: c(person("Stefan", "Widgren", role = c("aut", "cre"),
55
email = "stefan.widgren@gmail.com",
66
comment = c(ORCID = "0000-0001-5745-2284")),

NEWS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# SimInf (development version)
22

3+
## CHANGES OR IMPROVEMENTS
4+
5+
# SimInf 10.1.0 (2025-11-16)
6+
7+
## CHANGES OR IMPROVEMENTS
8+
9+
* Internal change to avoid using memcpy on zero-length continuous
10+
state vector, i.e., access elements of a 0-length R vector. This was
11+
uncovered by checks on M1mac system on CRAN.
12+
13+
# SimInf 10.0.0 (2025-11-13)
14+
315
## BREAKING CHANGES
416

517
Backwards incompatible changes that are the reason why the major
@@ -47,6 +59,9 @@ version has been incremented.
4759
* The `GNU Indent` program has been used to style the C code for
4860
consistency and readability.
4961

62+
* Add a function to calculate the Lambert W0 function using the GNU
63+
Scientific Library (GSL).
64+
5065
# SimInf 9.8.1 (2024-06-21)
5166

5267
## CHANGES OR IMPROVEMENTS

src/solvers/SimInf_solver.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,16 +1012,19 @@ SimInf_compartment_model_create(
10121012
const ptrdiff_t Nrep = args->Nrep;
10131013
const ptrdiff_t Nn = args->Nn;
10141014
const ptrdiff_t Nd = args->Nd;
1015-
model[0].v = malloc(Nrep * Nn * Nd * sizeof(double));
1015+
const ptrdiff_t v_len = Nrep * Nn * Nd * sizeof(double);
1016+
model[0].v = malloc(v_len);
10161017
if (!model[0].v)
10171018
goto on_error; /* #nocov */
1018-
model[0].v_new = malloc(Nrep * Nn * Nd * sizeof(double));
1019+
model[0].v_new = malloc(v_len);
10191020
if (!model[0].v_new)
10201021
goto on_error; /* #nocov */
10211022

10221023
/* Set continuous state to the initial state in each node. */
1023-
memcpy(model[0].v, args->v0, Nrep * Nn * Nd * sizeof(double));
1024-
memcpy(model[0].v_new, args->v0, Nrep * Nn * Nd * sizeof(double));
1024+
if (v_len > 0) {
1025+
memcpy(model[0].v, args->v0, v_len);
1026+
memcpy(model[0].v_new, args->v0, v_len);
1027+
}
10251028

10261029
/* Setup vector to keep track of nodes that must be updated due to
10271030
* scheduled events */

src/solvers/SimInf_solver_aem.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,16 @@ SimInf_solver_aem(
410410

411411
/* Copy continuous state to V */
412412
while (sa.V && sa.V_it < sa.tlen && sa.tt > sa.tspan[sa.V_it]) {
413-
memcpy(&sa.V[(ptrdiff_t) sa.Nd *
414-
(((ptrdiff_t) sa.Ntot * sa.V_it++) +
415-
sa.Ni)], sa.v_new,
416-
(ptrdiff_t) sa.Nn * (ptrdiff_t) sa.Nd *
417-
sizeof(double));
413+
const ptrdiff_t v_len = (ptrdiff_t) sa.Nn * (ptrdiff_t) sa.Nd *
414+
sizeof(double);
415+
if (v_len > 0) {
416+
memcpy(&sa.V[(ptrdiff_t) sa.Nd *
417+
(((ptrdiff_t) sa.Ntot * sa.V_it) +
418+
sa.Ni)],
419+
sa.v_new,
420+
v_len);
421+
}
422+
sa.V_it++;
418423
}
419424

420425
*&model[i] = sa;

src/solvers/SimInf_solver_mssm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ SimInf_solver_mssm(
288288

289289
/* Copy continuous state to V */
290290
while (m.V_it < m.tlen && m.tt > m.tspan[m.V_it]) {
291-
memcpy(&m.V[(ptrdiff_t) m.Nd * (ptrdiff_t) m.Ntot *
292-
m.V_it++], m.v_new,
293-
(ptrdiff_t) m.Nn * (ptrdiff_t) m.Nd *
294-
sizeof(double));
291+
const ptrdiff_t v_len = (ptrdiff_t) m.Nn * (ptrdiff_t) m.Nd *
292+
sizeof(double);
293+
if (v_len > 0) {
294+
memcpy(&m.V[(ptrdiff_t) m.Nd * (ptrdiff_t) m.Ntot * m.V_it],
295+
m.v_new,
296+
v_len);
297+
}
298+
m.V_it++;
295299
}
296300

297301
/* Swap the pointers to the continuous state

src/solvers/SimInf_solver_ssm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,14 @@ SimInf_solver_ssm(
295295

296296
/* Copy continuous state to V */
297297
while (m.V && m.V_it < m.tlen && m.tt > m.tspan[m.V_it]) {
298-
memcpy(&m.V[(ptrdiff_t) m.Nd *
299-
((m.Ntot * m.V_it++) + m.Ni)], m.v_new,
300-
(ptrdiff_t) m.Nn * (ptrdiff_t) m.Nd *
301-
sizeof(double));
298+
const ptrdiff_t v_len = (ptrdiff_t) m.Nn * (ptrdiff_t) m.Nd *
299+
sizeof(double);
300+
if (v_len > 0) {
301+
memcpy(&m.V[(ptrdiff_t) m.Nd * ((m.Ntot * m.V_it) + m.Ni)],
302+
m.v_new,
303+
v_len);
304+
}
305+
m.V_it++;
302306
}
303307

304308
*&model[i] = m;

0 commit comments

Comments
 (0)