You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nth=getDTthreads(nrow, true); // this nth is relied on in cleanup(); throttle=true/false debated for #5077
791
-
TMP=(int*)malloc(nth*UINT16_MAX*sizeof(int)); // used by counting sort (my_n<=65536) in radix_r()
792
-
UGRP=(uint8_t*)malloc(nth*256); // TODO: align TMP and UGRP to cache lines (and do the same for stack allocations too)
791
+
TMP=malloc(sizeof(*TMP)*nth*UINT16_MAX); // used by counting sort (my_n<=65536) in radix_r()
792
+
UGRP=malloc(sizeof(*UGRP)*nth*256); // TODO: align TMP and UGRP to cache lines (and do the same for stack allocations too)
793
793
if (!TMP|| !UGRP/*|| TMP%64 || UGRP%64*/) {
794
794
free(TMP); free(UGRP); // # nocov
795
795
STOP(_("Failed to allocate TMP or UGRP or they weren't cache line aligned: nth=%d"), nth); // # nocov
@@ -917,7 +917,7 @@ void radix_r(const int from, const int to, const int radix) {
917
917
#endif
918
918
919
919
uint8_t*restrict my_key=key[radix]+from; // safe to write as we don't use this radix again
920
-
uint8_t*o=(uint8_t*)malloc(my_n*sizeof(uint8_t));
920
+
uint8_t*o=malloc(sizeof(*o)*my_n);
921
921
if (!o)
922
922
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n*sizeof(uint8_t)), "o"); // # nocov
923
923
// if last key (i.e. radix+1==nradix) there are no more keys to reorder so we could reorder osub by reference directly and save allocating and populating o just
@@ -986,10 +986,10 @@ void radix_r(const int from, const int to, const int radix) {
986
986
}
987
987
if (!skip) {
988
988
// reorder osub and each remaining ksub
989
-
int*TMP=malloc(my_n*sizeof(int));
989
+
int*TMP=malloc(sizeof(*TMP) *my_n);
990
990
if (!TMP) {
991
991
free(o); // # nocov
992
-
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n*sizeof(int)), "TMP"); // # nocov
992
+
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(sizeof(*TMP) *my_n), "TMP"); // # nocov
993
993
}
994
994
constint*restrict osub=anso+from;
995
995
for (inti=0; i<my_n; i++) TMP[i] =osub[o[i]];
@@ -1009,9 +1009,9 @@ void radix_r(const int from, const int to, const int radix) {
1009
1009
return;
1010
1010
}
1011
1011
intngrp=0; //minor TODO: could know number of groups with certainty up above
1012
-
int*my_gs=malloc(my_n*sizeof(int));
1012
+
int*my_gs=malloc(sizeof(*my_gs) *my_n);
1013
1013
if (!my_gs)
1014
-
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n*sizeof(int)), "my_gs"); // # nocov
1014
+
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(sizeof(*my_gs) *my_n), "my_gs"); // # nocov
1015
1015
my_gs[ngrp]=1;
1016
1016
for (inti=1; i<my_n; i++) {
1017
1017
if (my_key[i]!=my_key[i-1]) my_gs[++ngrp] =1;
@@ -1111,7 +1111,7 @@ void radix_r(const int from, const int to, const int radix) {
1111
1111
if (!retgrp&&radix+1==nradix) {
1112
1112
return; // we're done. avoid allocating and populating very last group sizes for last key
1113
1113
}
1114
-
int*my_gs=malloc((ngrp==0 ? 256 : ngrp) *sizeof(int)); // ngrp==0 when sort and skip==true; we didn't count the non-zeros in my_counts yet in that case
1114
+
int*my_gs=malloc(sizeof(*my_gs) * (ngrp==0 ? 256 : ngrp)); // ngrp==0 when sort and skip==true; we didn't count the non-zeros in my_counts yet in that case
1115
1115
if (!my_gs)
1116
1116
STOP(_("Failed to allocate %d bytes for '%s'."), (int)((ngrp==0 ? 256 : ngrp) *sizeof(int)), "my_gs"); // # nocov
1117
1117
if (sortType!=0) {
@@ -1139,9 +1139,9 @@ void radix_r(const int from, const int to, const int radix) {
tmpType=(int8_t*)malloc((size_t)ncol*sizeof(int8_t)); // used i) in sampling to not stop on errors when bad jump point and ii) when accepting user overrides
1887
+
type=malloc(sizeof(*type)*(size_t)ncol);
1888
+
tmpType=malloc(sizeof(*tmpType)*(size_t)ncol); // used i) in sampling to not stop on errors when bad jump point and ii) when accepting user overrides
1889
1889
if (!type|| !tmpType) {
1890
1890
free(type); free(tmpType); // # nocov
1891
1891
STOP(_("Failed to allocate 2 x %d bytes for type and tmpType: %s"), ncol, strerror(errno)); // # nocov
@@ -2201,9 +2201,9 @@ int freadMain(freadMainArgs _args) {
2201
2201
rowSize1=0;
2202
2202
rowSize4=0;
2203
2203
rowSize8=0;
2204
-
size=(int8_t*)malloc((size_t)ncol*sizeof(int8_t)); // TODO: remove size[] when we implement Pasha's idea to += size inside processor
2204
+
size=malloc(sizeof(*size)*(size_t)ncol); // TODO: remove size[] when we implement Pasha's idea to += size inside processor
2205
2205
if (!size)
2206
-
STOP(_("Failed to allocate %d bytes for '%s': %s"), (int)(ncol*sizeof(int8_t)), "size", strerror(errno)); // # nocov
2206
+
STOP(_("Failed to allocate %d bytes for '%s': %s"), (int)(sizeof(*size)*(size_t)ncol), "size", strerror(errno)); // # nocov
2207
2207
nStringCols=0;
2208
2208
nNonStringCols=0;
2209
2209
for (intj=0; j<ncol; j++) {
@@ -2642,7 +2642,7 @@ int freadMain(freadMainArgs _args) {
2642
2642
DTPRINT(_(" Provided number of fill columns: %d but only found %d\n"), ncol, max_col);
// here we proceed as if fill=true for brevity (accounting for dups is tricky) and then catch any missings after this branch
72
72
// when use.names==NA we also proceed here as if use.names was TRUE to save new code and then check afterwards the map is 1:ncol for every item
73
73
// first find number of unique column names present; i.e. length(unique(unlist(lapply(l,names))))
74
-
SEXP*uniq=(SEXP*)malloc(upperBoundUniqueNames*sizeof(SEXP)); // upperBoundUniqueNames was initialized with 1 to ensure this is defined (otherwise 0 when no item has names)
74
+
SEXP*uniq=malloc(sizeof(*uniq)*upperBoundUniqueNames); // upperBoundUniqueNames was initialized with 1 to ensure this is defined (otherwise 0 when no item has names)
75
75
if (!uniq)
76
76
error(_("Failed to allocate upper bound of %"PRId64" unique column names [sum(lapply(l,ncol))]"), (int64_t)upperBoundUniqueNames); // # nocov
// ncol is now the final number of columns accounting for unique and dups across all colnames
130
130
// allocate a matrix: nrows==length(list) each entry contains which column to fetch for that final column
131
131
132
-
int*colMapRaw=(int*)malloc(LENGTH(l)*ncol*sizeof(int)); // the result of this scope used later
133
-
int*uniqMap=(int*)malloc(ncol*sizeof(int)); // maps the ith unique string to the first time it occurs in the final result
134
-
int*dupLink=(int*)malloc(ncol*sizeof(int)); // if a colname has occurred before (a dup) links from the 1st to the 2nd time in the final result, 2nd to 3rd, etc
132
+
int*colMapRaw=malloc(sizeof(*colMapRaw)*LENGTH(l)*ncol); // the result of this scope used later
133
+
int*uniqMap=malloc(sizeof(*uniqMap)*ncol); // maps the ith unique string to the first time it occurs in the final result
134
+
int*dupLink=malloc(sizeof(*dupLink)*ncol); // if a colname has occurred before (a dup) links from the 1st to the 2nd time in the final result, 2nd to 3rd, etc
135
135
if (!colMapRaw|| !uniqMap|| !dupLink) {
136
136
// # nocov start
137
137
for (inti=0; i<nuniq; ++i) SET_TRUELENGTH(uniq[i], 0);
// c( a<c<b, c<b<d<e ) => regular factor because this case isn't yet implemented. a<c<b<d<e would be possible in future (extending longest at the beginning or end)
378
378
constSEXP*sd=STRING_PTR_RO(longestLevels);
379
379
nLevel=allocLevel=longestLen;
380
-
levelsRaw=(SEXP*)malloc(nLevel*sizeof(SEXP));
380
+
levelsRaw=malloc(sizeof(*levelsRaw)*nLevel);
381
381
if (!levelsRaw) {
382
382
savetl_end(); // # nocov
383
383
error(_("Failed to allocate working memory for %d ordered factor levels of result column %d"), nLevel, idcol+j+1); // # nocov
0 commit comments