Skip to content

Commit

Permalink
check for String, and length one (closes #375)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Sep 21, 2015
1 parent 94f0e27 commit b5cbcf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2015-09-21 Dirk Eddelbuettel <edd@debian.org>

* inst/include/Rcpp/String.h: Before assigning ensure we received
exactly one string argument

2015-09-10 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION: Release 0.12.1
Expand Down
10 changes: 9 additions & 1 deletion inst/include/Rcpp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ namespace Rcpp {

/** construct a string from a single CHARSXP SEXP */
String(SEXP charsxp) : data(charsxp), valid(true), buffer_ready(false), enc(Rf_getCharCE(charsxp)) {
Rcpp_PreserveObject( data );
if (! ::Rf_isString(data))
throw ::Rcpp::not_compatible("expecting a string");
if (::Rf_length(data) != 1)
throw ::Rcpp::not_compatible("expecting a single value");
Rcpp_PreserveObject(data);
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
}

String(SEXP charsxp, const std::string& enc) : data(charsxp), valid(true), buffer_ready(false) {
if (! ::Rf_isString(data))
throw ::Rcpp::not_compatible("expecting a string");
if (::Rf_length(data) != 1)
throw ::Rcpp::not_compatible("expecting a single value");
Rcpp_PreserveObject( data );
set_encoding(enc);
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
Expand Down

0 comments on commit b5cbcf8

Please sign in to comment.