Index: DESCRIPTION =================================================================== --- DESCRIPTION (revision 453) +++ DESCRIPTION (working copy) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.2.4 +Version: 0.2.5 Date: $Date$ Author: Romain Francois and Dirk Eddelbuettel Maintainer: Romain and Dirk Index: src/mutators.cpp =================================================================== --- src/mutators.cpp (revision 453) +++ src/mutators.cpp (working copy) @@ -367,7 +367,7 @@ const Reflection * ref = message->GetReflection() ; - if( value == R_NilValue || LENGTH(value) == 0 ){ + if( value == R_NilValue || (Rf_isVector(value) && LENGTH(value) == 0 )) { ref->ClearField( message, field_desc ); return R_NilValue ; } Index: inst/unitTests/runit.nested.R =================================================================== --- inst/unitTests/runit.nested.R (revision 0) +++ inst/unitTests/runit.nested.R (revision 0) @@ -0,0 +1,16 @@ +.setUp <- function(){ + if( ! exists( "NestedOuter", "RProtoBuf:DescriptorPool" ) ) { + # None of the messages in unittest.proto is exactly right to tickle this bug. + unitest.proto.file <- system.file( "unitTests", "data", "nested.proto", package = "RProtoBuf" ) + readProtoFiles(file = unitest.proto.file) + } +} + +# RProtoBuf before v0.2.5 had a bug whereby uninitialized memory was read and used +# to determine whether or not to update a nested message field in new() / update(). +test.nested <- function() { + for (i in 1:1000) { + q <- new(NestedOuter, b=new(NestedInner, x=1)) + checkTrue(q$isInitialized()) + } +} Index: inst/unitTests/data/nested.proto =================================================================== --- inst/unitTests/data/nested.proto (revision 0) +++ inst/unitTests/data/nested.proto (revision 0) @@ -0,0 +1,6 @@ +message NestedInner { + required int32 x = 1; +} +message NestedOuter { + required NestedInner b = 1; +}