Skip to content

Commit c1ba69e

Browse files
in getidcols() too
1 parent f35cb95 commit c1ba69e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/fmelt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)