@@ -552,23 +552,23 @@ SEXP getvaluecols(SEXP DT, SEXP dtnames, Rboolean valfactor, Rboolean verbose, s
552552 //TODO complex value type: case CPLXSXP: { } break;
553553 case REALSXP : {
554554 double * dtarget = REAL (target );
555- const double * dthiscol = REAL (thiscol );
555+ const double * dthiscol = REAL_RO (thiscol );
556556 if (data -> narm ) {
557557 for (int k = 0 ; k < thislen ; ++ k )
558558 dtarget [counter + k ] = dthiscol [ithisidx [k ]- 1 ];
559- } else {
559+ } else if ( data -> nrow ) {
560560 memcpy (dtarget + j * data -> nrow , dthiscol , data -> nrow * size );
561561 }
562562 }
563563 break ;
564564 case INTSXP :
565565 case LGLSXP : {
566566 int * itarget = INTEGER (target );
567- const int * ithiscol = INTEGER (thiscol );
567+ const int * ithiscol = INTEGER_RO (thiscol );
568568 if (data -> narm ) {
569569 for (int k = 0 ; k < thislen ; ++ k )
570570 itarget [counter + k ] = ithiscol [ithisidx [k ]- 1 ];
571- } else {
571+ } else if ( data -> nrow ) {
572572 memcpy (itarget + j * data -> nrow , ithiscol , data -> nrow * size );
573573 }
574574 } break ;
@@ -704,7 +704,7 @@ SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data
704704 switch (TYPEOF (thiscol )) {
705705 case REALSXP : {
706706 double * dtarget = REAL (target );
707- const double * dthiscol = REAL (thiscol );
707+ const double * dthiscol = REAL_RO (thiscol );
708708 if (data -> narm ) {
709709 for (int j = 0 ; j < data -> lmax ; ++ j ) {
710710 SEXP thisidx = VECTOR_ELT (data -> not_NA_indices , j );
@@ -714,7 +714,7 @@ SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data
714714 dtarget [counter + k ] = dthiscol [ithisidx [k ]- 1 ];
715715 counter += thislen ;
716716 }
717- } else {
717+ } else if ( data -> nrow ) {
718718 for (int j = 0 ; j < data -> lmax ; ++ j )
719719 memcpy (dtarget + j * data -> nrow , dthiscol , data -> nrow * size );
720720 }
@@ -723,7 +723,7 @@ SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data
723723 case INTSXP :
724724 case LGLSXP : {
725725 int * itarget = INTEGER (target );
726- const int * ithiscol = INTEGER (thiscol );
726+ const int * ithiscol = INTEGER_RO (thiscol );
727727 if (data -> narm ) {
728728 for (int j = 0 ; j < data -> lmax ; ++ j ) {
729729 SEXP thisidx = VECTOR_ELT (data -> not_NA_indices , j );
@@ -733,7 +733,7 @@ SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data
733733 itarget [counter + k ] = ithiscol [ithisidx [k ]- 1 ];
734734 counter += thislen ;
735735 }
736- } else {
736+ } else if ( data -> nrow ) {
737737 for (int j = 0 ; j < data -> lmax ; ++ j )
738738 memcpy (itarget + j * data -> nrow , ithiscol , data -> nrow * size );
739739 }
0 commit comments