Skip to content

Commit b5cbcf8

Browse files
committed
check for String, and length one (closes #375)
1 parent 94f0e27 commit b5cbcf8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2015-09-21 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/String.h: Before assigning ensure we received
4+
exactly one string argument
5+
16
2015-09-10 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION: Release 0.12.1

inst/include/Rcpp/String.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ namespace Rcpp {
7272

7373
/** construct a string from a single CHARSXP SEXP */
7474
String(SEXP charsxp) : data(charsxp), valid(true), buffer_ready(false), enc(Rf_getCharCE(charsxp)) {
75-
Rcpp_PreserveObject( data );
75+
if (! ::Rf_isString(data))
76+
throw ::Rcpp::not_compatible("expecting a string");
77+
if (::Rf_length(data) != 1)
78+
throw ::Rcpp::not_compatible("expecting a single value");
79+
Rcpp_PreserveObject(data);
7680
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
7781
}
7882

7983
String(SEXP charsxp, const std::string& enc) : data(charsxp), valid(true), buffer_ready(false) {
84+
if (! ::Rf_isString(data))
85+
throw ::Rcpp::not_compatible("expecting a string");
86+
if (::Rf_length(data) != 1)
87+
throw ::Rcpp::not_compatible("expecting a single value");
8088
Rcpp_PreserveObject( data );
8189
set_encoding(enc);
8290
RCPP_STRING_DEBUG( "String(SEXP)" ) ;

0 commit comments

Comments
 (0)