From 15072099bc37c2fa677914b236f77f793cd7b74e Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 13 Mar 2020 14:31:08 +0800 Subject: [PATCH 01/23] add whitespace to remove spurious coverage of inlined src/ error branches --- src/assign.c | 93 ++++++++++++++++++++----------- src/bmerge.c | 48 ++++++++++------ src/dogroups.c | 54 ++++++++++++------ src/fcast.c | 3 +- src/fmelt.c | 66 ++++++++++++++-------- src/forder.c | 18 ++++-- src/frank.c | 15 +++-- src/freadR.c | 6 +- src/fsort.c | 12 ++-- src/fwriteR.c | 6 +- src/gsumm.c | 135 ++++++++++++++++++++++++++++++--------------- src/ijoin.c | 33 +++++++---- src/init.c | 93 ++++++++++++++++++++----------- src/nafill.c | 3 +- src/openmp-utils.c | 12 ++-- src/rbindlist.c | 50 +++++++++++------ src/reorder.c | 12 ++-- src/shift.c | 11 +++- src/subset.c | 33 +++++++---- src/uniqlist.c | 42 +++++++++----- src/utils.c | 5 +- src/vecseq.c | 18 ++++-- src/wrappers.c | 15 +++-- 23 files changed, 523 insertions(+), 260 deletions(-) diff --git a/src/assign.c b/src/assign.c index 1392079e72..bb1d929e51 100644 --- a/src/assign.c +++ b/src/assign.c @@ -4,12 +4,15 @@ static void finalizer(SEXP p) { SEXP x; R_len_t n, l, tl; - if(!R_ExternalPtrAddr(p)) error(_("Internal error: finalizer hasn't received an ExternalPtr")); // # nocov + if(!R_ExternalPtrAddr(p)) + error(_("Internal error: finalizer hasn't received an ExternalPtr")); // # nocov p = R_ExternalPtrTag(p); - if (!isString(p)) error(_("Internal error: finalizer's ExternalPtr doesn't see names in tag")); // # nocov + if (!isString(p)) + error(_("Internal error: finalizer's ExternalPtr doesn't see names in tag")); // # nocov l = LENGTH(p); tl = TRUELENGTH(p); - if (l<0 || tl0 but 0 but l) ? n : l); // e.g. test 848 and 851 in R > 3.0.2 // added (n>l) ? ... for #970, see test 1481. @@ -212,8 +222,10 @@ SEXP alloccol(SEXP dt, R_len_t n, Rboolean verbose) tl = TRUELENGTH(dt); // R <= 2.13.2 and we didn't catch uninitialized tl somehow - if (tl<0) error(_("Internal error, tl of class is marked but tl<0.")); // # nocov - if (tl>0 && tl0 && tll+10000) warning(_("tl (%d) is greater than 10,000 items over-allocated (l = %d). If you didn't set the datatable.alloccol option to be very large, please report to data.table issue tracker including the result of sessionInfo()."),tl,l); if (n>tl) return(shallow(dt,R_NilValue,n)); // usual case (increasing alloc) if (n0) { - if (!isDataTable) error(_("set() on a data.frame is for changing existing columns, not adding new ones. Please use a data.table for that. data.table's are over-allocated and don't shallow copy.")); + if (!isDataTable) + error(_("set() on a data.frame is for changing existing columns, not adding new ones. Please use a data.table for that. data.table's are over-allocated and don't shallow copy.")); newcolnames = PROTECT(allocVector(STRSXP, k)); protecti++; for (i=0; i1; // initial value; may be revised below if (verbose) Rprintf(_("RHS_list_of_columns == %s\n"), RHS_list_of_columns ? "true" : "false"); if (TYPEOF(values)==VECSXP && length(cols)==1 && length(values)==1) { @@ -400,13 +419,16 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) for (i=0; ioldncol+length(newcolnames)) { - if (!isDataTable) error(_("Item %d of column numbers in j is %d which is outside range [1,ncol=%d]. set() on a data.frame is for changing existing columns, not adding new ones. Please use a data.table for that."), i+1, coln, oldncol); - else error(_("Item %d of column numbers in j is %d which is outside range [1,ncol=%d]. Use column names instead in j to add new columns."), i+1, coln, oldncol); + if (!isDataTable) + error(_("Item %d of column numbers in j is %d which is outside range [1,ncol=%d]. set() on a data.frame is for changing existing columns, not adding new ones. Please use a data.table for that."), i+1, coln, oldncol); + else + error(_("Item %d of column numbers in j is %d which is outside range [1,ncol=%d]. Use column names instead in j to add new columns."), i+1, coln, oldncol); } coln--; SEXP thisvalue = RHS_list_of_columns ? VECTOR_ELT(values, i) : values; vlen = length(thisvalue); - if (isNull(thisvalue) && !isNull(rows)) error(_("When deleting columns, i should not be provided")); // #1082, #3089 + if (isNull(thisvalue) && !isNull(rows)) + error(_("When deleting columns, i should not be provided")); // #1082, #3089 if (coln+1 <= oldncol) colnam = STRING_ELT(names,coln); else colnam = STRING_ELT(newcolnames,coln-length(names)); if (coln+1 <= oldncol && isNull(thisvalue)) continue; // delete existing column(s) afterwards, near end of this function @@ -444,7 +466,8 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) oldtncol = TRUELENGTH(dt); // TO DO: oldtncol can be just called tl now, as we won't realloc here any more. if (oldtncololdncol+10000L) warning(_("truelength (%d) is greater than 10,000 items over-allocated (length = %d). See ?truelength. If you didn't set the datatable.alloccol option very large, please report to data.table issue tracker including the result of sessionInfo()."),oldtncol, oldncol); @@ -466,7 +489,8 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) coln = INTEGER(cols)[i]-1; SEXP thisvalue = RHS_list_of_columns ? VECTOR_ELT(values, i) : values; if (TYPEOF(thisvalue)==NILSXP) { - if (!isNull(rows)) error(_("Internal error: earlier error 'When deleting columns, i should not be provided' did not happen.")); // # nocov + if (!isNull(rows)) + error(_("Internal error: earlier error 'When deleting columns, i should not be provided' did not happen.")); // # nocov ndelete++; continue; // delete column(s) afterwards, below this loop } @@ -559,7 +583,8 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) continue; // with next index } tc1 += 2; // tc1 always marks the start of a key column - if (!*tc1) error(_("Internal error: index name ends with trailing __")); // # nocov + if (!*tc1) + error(_("Internal error: index name ends with trailing __")); // # nocov // check the position of the first appearance of an assigned column in the index. // the new index will be truncated to this position. char *s4 = (char*) malloc(strlen(c1) + 3); @@ -810,7 +835,8 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con SEXP s = sourceLevelsD[k]; int tl = TRUELENGTH(s); if (tl) { // tl negative here - if (tl != -nTargetLevels-thisAdd-1) error(_("Internal error: extra level check sum failed")); // # nocov + if (tl != -nTargetLevels-thisAdd-1) + error(_("Internal error: extra level check sum failed")); // # nocov temp[thisAdd++] = s; SET_TRUELENGTH(s,0); } @@ -1204,13 +1230,18 @@ void savetl_end() { SEXP setcharvec(SEXP x, SEXP which, SEXP newx) { int w; - if (!isString(x)) error(_("x must be a character vector")); - if (!isInteger(which)) error(_("'which' must be an integer vector")); - if (!isString(newx)) error(_("'new' must be a character vector")); - if (LENGTH(newx)!=LENGTH(which)) error(_("'new' is length %d. Should be the same as length of 'which' (%d)"),LENGTH(newx),LENGTH(which)); + if (!isString(x)) + error(_("x must be a character vector")); + if (!isInteger(which)) + error(_("'which' must be an integer vector")); + if (!isString(newx)) + error(_("'new' must be a character vector")); + if (LENGTH(newx)!=LENGTH(which)) + error(_("'new' is length %d. Should be the same as length of 'which' (%d)"),LENGTH(newx),LENGTH(which)); for (int i=0; iLENGTH(x)) error(_("Item %d of 'which' is %d which is outside range of the length %d character vector"), i+1,w,LENGTH(x)); + if (w==NA_INTEGER || w<1 || w>LENGTH(x)) + error(_("Item %d of 'which' is %d which is outside range of the length %d character vector"), i+1,w,LENGTH(x)); SET_STRING_ELT(x, w-1, STRING_ELT(newx, i)); } return R_NilValue; diff --git a/src/bmerge.c b/src/bmerge.c index 15d7d6f4f7..0895d287f6 100644 --- a/src/bmerge.c +++ b/src/bmerge.c @@ -45,33 +45,44 @@ SEXP bmerge(SEXP iArg, SEXP xArg, SEXP icolsArg, SEXP xcolsArg, SEXP isorted, SE // iArg, xArg, icolsArg and xcolsArg i = iArg; x = xArg; // set globals so bmerge_r can see them. - if (!isInteger(icolsArg)) error(_("Internal error: icols is not integer vector")); // # nocov - if (!isInteger(xcolsArg)) error(_("Internal error: xcols is not integer vector")); // # nocov - if (LENGTH(icolsArg) > LENGTH(xcolsArg)) error(_("Internal error: length(icols) [%d] > length(xcols) [%d]"), LENGTH(icolsArg), LENGTH(xcolsArg)); // # nocov + if (!isInteger(icolsArg)) + error(_("Internal error: icols is not integer vector")); // # nocov + if (!isInteger(xcolsArg)) + error(_("Internal error: xcols is not integer vector")); // # nocov + if (LENGTH(icolsArg) > LENGTH(xcolsArg)) + error(_("Internal error: length(icols) [%d] > length(xcols) [%d]"), LENGTH(icolsArg), LENGTH(xcolsArg)); // # nocov icols = INTEGER(icolsArg); xcols = INTEGER(xcolsArg); xN = LENGTH(x) ? LENGTH(VECTOR_ELT(x,0)) : 0; iN = ilen = anslen = LENGTH(i) ? LENGTH(VECTOR_ELT(i,0)) : 0; ncol = LENGTH(icolsArg); // there may be more sorted columns in x than involved in the join for(int col=0; colLENGTH(i) || icols[col]<1) error(_("icols[%d]=%d outside range [1,length(i)=%d]"), col, icols[col], LENGTH(i)); - if (xcols[col]>LENGTH(x) || xcols[col]<1) error(_("xcols[%d]=%d outside range [1,length(x)=%d]"), col, xcols[col], LENGTH(x)); + if (icols[col]==NA_INTEGER) + error(_("Internal error. icols[%d] is NA"), col); // # nocov + if (xcols[col]==NA_INTEGER) + error(_("Internal error. xcols[%d] is NA"), col); // # nocov + if (icols[col]>LENGTH(i) || icols[col]<1) + error(_("icols[%d]=%d outside range [1,length(i)=%d]"), col, icols[col], LENGTH(i)); + if (xcols[col]>LENGTH(x) || xcols[col]<1) + error(_("xcols[%d]=%d outside range [1,length(x)=%d]"), col, xcols[col], LENGTH(x)); int it = TYPEOF(VECTOR_ELT(i, icols[col]-1)); int xt = TYPEOF(VECTOR_ELT(x, xcols[col]-1)); - if (iN && it!=xt) error(_("typeof x.%s (%s) != typeof i.%s (%s)"), CHAR(STRING_ELT(getAttrib(x,R_NamesSymbol),xcols[col]-1)), type2char(xt), CHAR(STRING_ELT(getAttrib(i,R_NamesSymbol),icols[col]-1)), type2char(it)); + if (iN && it!=xt) + error(_("typeof x.%s (%s) != typeof i.%s (%s)"), CHAR(STRING_ELT(getAttrib(x,R_NamesSymbol),xcols[col]-1)), type2char(xt), CHAR(STRING_ELT(getAttrib(i,R_NamesSymbol),icols[col]-1)), type2char(it)); } // raise(SIGINT); // rollArg, rollendsArg roll = 0.0; rollToNearest = FALSE; if (isString(rollarg)) { - if (strcmp(CHAR(STRING_ELT(rollarg,0)),"nearest") != 0) error(_("roll is character but not 'nearest'")); - if (TYPEOF(VECTOR_ELT(i, icols[ncol-1]-1))==STRSXP) error(_("roll='nearest' can't be applied to a character column, yet.")); + if (strcmp(CHAR(STRING_ELT(rollarg,0)),"nearest") != 0) + error(_("roll is character but not 'nearest'")); + if (TYPEOF(VECTOR_ELT(i, icols[ncol-1]-1))==STRSXP) + error(_("roll='nearest' can't be applied to a character column, yet.")); roll=1.0; rollToNearest=TRUE; // the 1.0 here is just any non-0.0, so roll!=0.0 can be used later } else { - if (!isReal(rollarg)) error(_("Internal error: roll is not character or double")); // # nocov + if (!isReal(rollarg)) + error(_("Internal error: roll is not character or double")); // # nocov roll = REAL(rollarg)[0]; // more common case (rolling forwards or backwards) or no roll when 0.0 } rollabs = fabs(roll); @@ -153,7 +164,8 @@ SEXP bmerge(SEXP iArg, SEXP xArg, SEXP icolsArg, SEXP xcolsArg, SEXP isorted, SE // xo arg xo = NULL; if (length(xoArg)) { - if (!isInteger(xoArg)) error(_("Internal error: xoArg is not an integer vector")); // # nocov + if (!isInteger(xoArg)) + error(_("Internal error: xoArg is not an integer vector")); // # nocov xo = INTEGER(xoArg); } @@ -268,7 +280,8 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg case LT : xupp = xlow + 1; xlow = xlowIn; break; case GE : if (ival.i != NA_INTEGER) xupp = xuppIn; break; case GT : xlow = xupp - 1; if (ival.i != NA_INTEGER) xupp = xuppIn; break; - default : error(_("Internal error in bmerge_r for '%s' column. Unrecognized value op[col]=%d"), type2char(TYPEOF(xc)), op[col]); // #nocov + default : + error(_("Internal error in bmerge_r for '%s' column. Unrecognized value op[col]=%d"), type2char(TYPEOF(xc)), op[col]); // #nocov } // for LE/LT cases, we need to ensure xlow excludes NA indices, != EQ is checked above already if (op[col] <= 3 && xlowxuppIn) error(_("Internal error: xlow!=xupp-1 || xlowxuppIn")); // # nocov + if (xlow != xupp-1 || xlowxuppIn) + error(_("Internal error: xlow!=xupp-1 || xlowxuppIn")); // # nocov if (rollToNearest) { // value of roll ignored currently when nearest if ( (!lowmax || xlow>xlowIn) && (!uppmax || xupp