Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: hesim
Type: Package
Title: Health Economic Simulation Modeling and Decision Analysis
Version: 0.5.6
Version: 0.5.7
Authors@R: c(
person("Devin", "Incerti", , "devin.incerti@gmail.com", role = c("aut", "cre")),
person("Jeroen P.", "Jansen", role = "aut"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## hesim 0.5.7
Fix memory access issue identified in piecewise exponential distributions by
ensuring that the `time` and `rate` vectors are of the same length. Previously,
an off-by-one allocation could cause undefined behavior on some systems.

## hesim 0.5.6
Ensure compatibility with `ggplot v4.0.0`.

Expand Down
9 changes: 5 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Release summary
The purpose of this release is to fix errors caused by the latest release of
ggplot2. This is a resubmission that:
The purpose of this release is to fix memory access issues identified by
`clang-ASAN` and `gcc-ASAN` during the CRAN checks.

1. Updates a broken link for the data.table website.
2. Ensures all examples complete in under 10 seconds during CRAN checks.
The error was first reproduced on R-hub `clang-asan` and `gcc-asan`. After
the fix, it was then confirmed that `clang-asan` and `gcc-asan` did not
produce any errors.

## R CMD check results
0 errors | 0 warnings | 0 notes
2 changes: 1 addition & 1 deletion inst/include/hesim/statmods/statmods.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class surv : public statmod {
}
else if (dist_name == "pwexp"){
int n_times = params_surv.pwexp_aux_.time_.size();
std::vector<double> rate(n_times + 1, 0.0);
std::vector<double> rate(n_times, 0.0);
d = new stats::piecewise_exponential(rate,
params_surv.pwexp_aux_.time_);
}
Expand Down
21 changes: 21 additions & 0 deletions inst/include/hesim/stats/distributions.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,34 @@ class piecewise_exponential : public distribution {
std::vector<double> cumrate_; ///< cumulative rate parameter up to each time
std::vector<double> time_; ///<A vector equal to the number of elements in rate
/// giving the times at which the rate changes

/**
* Check that the time and rate vectors have the same length.
*
* @param time Vector of times at which the rate changes.
* @param rate Vector of rate parameters.
*
* @throws Rcpp::stop if time and rate vectors are not the same length.
*/
void check_same_length(const std::vector<double>& time, const std::vector<double>& rate) {
if (time.size() != rate.size()) {
std::ostringstream oss_time, oss_rate;
for (auto x : time) oss_time << x << " ";
for (auto x : rate) oss_rate << x << " ";
Rcpp::stop("'time' and 'rate' must be the same length.\n" +
std::string("time: ") + oss_time.str() + "\n" +
std::string("rate: ") + oss_rate.str());
}
}

public:
/**
* The constructor.
* Instantiates an exponential distribution with a given rate parameter.
*/
piecewise_exponential(std::vector<double> rate, std::vector<double> time){
check_same_length(time, rate);

rate_ = rate;
time_ = time;
cumrate_.resize(rate_.size());
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-cpp-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ test_that("pwexp", {
expect_true(all(r >= max(time) + 1))
})

# An error is thrown if time and rate are not the same length
expect_error(
new(PwExp, rate = c(1, 2), time = c(0, 2, 4)),
"'time' and 'rate' must be the same length."
)


# Weibull distribution (AFT) ---------------------------------------------------
test_that("weibull", {
Weibull <- module$weibull
Expand Down