[Rprotobuf-commits] r478 - in pkg: inst/unitTests src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 22 06:56:51 CEST 2012


Author: murray
Date: 2012-08-22 06:56:50 +0200 (Wed, 22 Aug 2012)
New Revision: 478

Modified:
   pkg/inst/unitTests/runit.golden.message.R
   pkg/src/mutators.cpp
Log:
Add better input checking when setting an optional field to avoid an
uncaught exception that would kill the R session, and add a test.



Modified: pkg/inst/unitTests/runit.golden.message.R
===================================================================
--- pkg/inst/unitTests/runit.golden.message.R	2012-08-21 18:09:08 UTC (rev 477)
+++ pkg/inst/unitTests/runit.golden.message.R	2012-08-22 04:56:50 UTC (rev 478)
@@ -75,3 +75,9 @@
         # Verify that we don't silently cast NA into TRUE or FALSE.
         checkException(test$add("repeated_bool"), c(TRUE, FALSE, NA))
 }
+
+# Versions of RProtoBuf <= 0.2.5 would terminate the R instance with unhandled Rcpp exceptions.
+test.invalidAssignments <- function(){
+	test <- new(protobuf_unittest.TestAllTypes)
+	checkException(test$optional_int32 <- 1:10)
+}

Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp	2012-08-21 18:09:08 UTC (rev 477)
+++ pkg/src/mutators.cpp	2012-08-22 04:56:50 UTC (rev 478)
@@ -993,6 +993,9 @@
 		// }}}
 	} else {
 		// {{{ non repeated fields
+		if (Rf_isVector(value) && LENGTH(value) > 1) {
+			throwException( "cannot set non-repeated field to vector of length > 1", "CastException" ) ;
+		}
 		switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){
 			// {{{ simple cases using macro expansion
 #undef HANDLE_SINGLE_FIELD



More information about the Rprotobuf-commits mailing list