Skip to content

Commit

Permalink
Fixed undefined behaviour issues with negative sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
djvanderlaan committed May 16, 2018
1 parent a766e3e commit 0e39cea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lvec
Type: Package
Title: Out of Memory Vectors
Version: 0.2.0
Version: 0.2.1
Date: 2018-05-15
Author: Jan van der Laan
Maintainer: Jan van der Laan <djvanderlaan@unrealizedtime.nl>
Expand Down
2 changes: 2 additions & 0 deletions src/assign_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ RcppExport SEXP assign_range(SEXP rv, SEXP rindex, SEXP rvalues) {
throw Rcpp::exception("Missing value for lower bound of range.");
if (index.is_na(index[1]))
throw Rcpp::exception("Missing value for upper bound of range.");
if (index[0] < 1 || index[1] < 1)
throw Rcpp::exception("Index out of range.");
// create and call visitor
assign_range_visitor visitor{static_cast<ldat::vec::vecsize>(index[0]-1),
static_cast<ldat::vec::vecsize>(index[1]-1), *values};
Expand Down
1 change: 1 addition & 0 deletions src/construct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RcppExport SEXP new_lvec(SEXP rsize, SEXP rtype, SEXP rstrlen) {
BEGIN_RCPP
double size = Rcpp::as<double>(rsize);
if (Rcpp::NumericVector::is_na(size)) throw Rcpp::exception("Size is not a number.");
if (size < 0) throw Rcpp::exception("Size is smaller than 0");
if (size > ldat::max_index) throw Rcpp::exception("Size is too large.");
std::string type = Rcpp::as<std::string>(rtype);

Expand Down
2 changes: 2 additions & 0 deletions src/indexing_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ RcppExport SEXP get_range(SEXP rv, SEXP rindex) {
throw Rcpp::exception("Missing value for lower bound of range.");
if (ldat::is_na(index[1]))
throw Rcpp::exception("Missing value for upper bound of range.");
if (index[0] < 1 || index[1] < 1)
throw Rcpp::exception("Index out of range.");
// index
range_indexing_visitor visitor{static_cast<ldat::vec::vecsize>(index[0]-1),
static_cast<ldat::vec::vecsize>(index[1]-1)};
Expand Down

0 comments on commit 0e39cea

Please sign in to comment.