@@ -117,7 +117,7 @@ static void push(const int *x, const int n) {
117117 int newn = gs_thread_n [me ] + n ;
118118 if (gs_thread_alloc [me ] < newn ) {
119119 gs_thread_alloc [me ] = (newn < nrow /3 ) ? (1 + (newn * 2 )/4096 )* 4096 : nrow ; // [2|3] to not overflow and 3 not 2 to avoid allocating close to nrow (nrow groups occurs when all size 1 groups)
120- gs_thread [me ] = realloc (gs_thread [me ], gs_thread_alloc [me ]* sizeof ( int ) );
120+ gs_thread [me ] = realloc (gs_thread [me ], sizeof ( * gs_thread [me ]) * gs_thread_alloc [ me ] );
121121 if (gs_thread [me ]== NULL ) STOP (_ ("Failed to realloc thread private group size buffer to %d*4bytes" ), (int )gs_thread_alloc [me ]);
122122 }
123123 memcpy (gs_thread [me ]+ gs_thread_n [me ], x , n * sizeof (int ));
@@ -131,10 +131,10 @@ static void flush(void) {
131131 int newn = gs_n + n ;
132132 if (gs_alloc < newn ) {
133133 gs_alloc = (newn < nrow /3 ) ? (1 + (newn * 2 )/4096 )* 4096 : nrow ;
134- gs = realloc (gs , gs_alloc * sizeof (int ) );
134+ gs = realloc (gs , sizeof (* gs ) * gs_alloc );
135135 if (gs == NULL ) STOP (_ ("Failed to realloc group size result to %d*4bytes" ), (int )gs_alloc );
136136 }
137- memcpy (gs + gs_n , gs_thread [me ], n * sizeof (int ));
137+ memcpy (gs + gs_n , gs_thread [me ], sizeof (int )* n );
138138 gs_n += n ;
139139 gs_thread_n [me ] = 0 ;
140140}
@@ -316,7 +316,7 @@ static void range_str(const SEXP *x, int n, uint64_t *out_min, uint64_t *out_max
316316 if (ustr_alloc <=ustr_n ) {
317317 ustr_alloc = (ustr_alloc == 0 ) ? 16384 : ustr_alloc * 2 ; // small initial guess, negligible time to alloc 128KB (32 pages)
318318 if (ustr_alloc > n ) ustr_alloc = n ; // clamp at n. Reaches n when fully unique (no dups)
319- ustr = realloc (ustr , ustr_alloc * sizeof (SEXP ));
319+ ustr = realloc (ustr , sizeof (SEXP ) * ustr_alloc );
320320 if (ustr == NULL ) STOP (_ ("Unable to realloc %d * %d bytes in range_str" ), ustr_alloc , (int )sizeof (SEXP )); // # nocov
321321 }
322322 ustr [ustr_n ++ ] = s ;
@@ -345,7 +345,7 @@ static void range_str(const SEXP *x, int n, uint64_t *out_min, uint64_t *out_max
345345 SEXP * ustr3 = malloc (sizeof (* ustr3 ) * ustr_n );
346346 if (!ustr3 )
347347 STOP (_ ("Failed to alloc ustr3 when converting strings to UTF8" )); // # nocov
348- memcpy (ustr3 , STRING_PTR_RO (ustr2 ), ustr_n * sizeof (SEXP ));
348+ memcpy (ustr3 , STRING_PTR_RO (ustr2 ), sizeof (SEXP ) * ustr_n );
349349 // need to reset ustr_maxlen because we need ustr_maxlen for utf8 strings
350350 ustr_maxlen = 0 ;
351351 for (int i = 0 ; i < ustr_n ; i ++ ) {
@@ -551,9 +551,9 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
551551
552552 int ncol = length (by );
553553 int keyAlloc = (ncol + n_cplx )* 8 + 1 ; // +1 for NULL to mark end; calloc to initialize with NULLs
554- key = calloc (keyAlloc , sizeof (uint8_t * )); // needs to be before loop because part II relies on part I, column-by-column.
554+ key = calloc (keyAlloc , sizeof (* key )); // needs to be before loop because part II relies on part I, column-by-column.
555555 if (!key )
556- STOP (_ ("Unable to allocate %" PRIu64 " bytes of working memory" ), (uint64_t )keyAlloc * sizeof (uint8_t * )); // # nocov
556+ STOP (_ ("Unable to allocate %" PRIu64 " bytes of working memory" ), (uint64_t )keyAlloc * sizeof (* key )); // # nocov
557557 nradix = 0 ; // the current byte we're writing this column to; might be squashing into it (spare>0)
558558 int spare = 0 ; // the amount of bits remaining on the right of the current nradix byte
559559 bool isReal = false;
@@ -665,10 +665,10 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
665665
666666 for (int b = 0 ; b < nbyte ; b ++ ) {
667667 if (key [nradix + b ]== NULL ) {
668- uint8_t * tt = calloc (nrow , sizeof (uint8_t )); // 0 initialize so that NA's can just skip (NA is always the 0 offset)
668+ uint8_t * tt = calloc (nrow , sizeof (* tt )); // 0 initialize so that NA's can just skip (NA is always the 0 offset)
669669 if (!tt ) {
670670 free (key ); // # nocov
671- STOP (_ ("Unable to allocate %" PRIu64 " bytes of working memory" ), (uint64_t )nrow * sizeof (uint8_t )); // # nocov
671+ STOP (_ ("Unable to allocate %" PRIu64 " bytes of working memory" ), (uint64_t )nrow * sizeof (* tt )); // # nocov
672672 }
673673 key [nradix + b ] = tt ;
674674 }
@@ -796,9 +796,9 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
796796 }
797797
798798 if (retgrp ) {
799- gs_thread = calloc (nth , sizeof (int * )); // thread private group size buffers
800- gs_thread_alloc = calloc (nth , sizeof (int ));
801- gs_thread_n = calloc (nth , sizeof (int ));
799+ gs_thread = calloc (nth , sizeof (* gs_thread )); // thread private group size buffers
800+ gs_thread_alloc = calloc (nth , sizeof (* gs_thread_alloc ));
801+ gs_thread_n = calloc (nth , sizeof (* gs_thread_n ));
802802 if (!gs_thread || !gs_thread_alloc || !gs_thread_n ) {
803803 free (gs_thread ); free (gs_thread_alloc ); free (gs_thread_n ); // # nocov
804804 STOP (_ ("Could not allocate (very tiny) group size thread buffers" )); // # nocov
@@ -1242,9 +1242,9 @@ void radix_r(const int from, const int to, const int radix) {
12421242 // the counts are uint16_t but the cumulate needs to be int32_t (or int64_t in future) to hold the offsets
12431243 // If skip==true and we're already done, we still need the first row of this cummulate (diff to get total group sizes) to push() or recurse below
12441244
1245- int * starts = calloc (nBatch * 256 , sizeof (int )); // keep starts the same shape and ugrp order as counts
1245+ int * starts = calloc (nBatch * 256 , sizeof (* starts )); // keep starts the same shape and ugrp order as counts
12461246 if (!starts )
1247- STOP (_ ("Failed to allocate %d bytes for '%s'." ), (int )(nBatch * 256 * sizeof (int )), "starts" ); // # nocov
1247+ STOP (_ ("Failed to allocate %d bytes for '%s'." ), (int )(nBatch * 256 * sizeof (* starts )), "starts" ); // # nocov
12481248 for (int j = 0 , sum = 0 ; j < ngrp ; j ++ ) { // iterate through columns (ngrp bytes)
12491249 uint16_t * tmp1 = counts + ugrp [j ];
12501250 int * tmp2 = starts + ugrp [j ];
0 commit comments