Skip to content

Commit

Permalink
Use %zu for sizeof() formats (#5791)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 6, 2023
1 parent 4fcf81c commit 3535631
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con
// # nocov start
for (int k=0; k<nSourceLevels; ++k) SET_TRUELENGTH(sourceLevelsD[k], 0);
savetl_end();
error(_("Unable to allocate working memory of %lu bytes to combine factor levels"), nAdd*sizeof(SEXP *));
error(_("Unable to allocate working memory of %zu bytes to combine factor levels"), nAdd*sizeof(SEXP *));
// # nocov end
}
for (int k=0, thisAdd=0; thisAdd<nAdd; ++k) { // thisAdd<nAdd to stop early when the added ones are all reached
Expand Down
6 changes: 3 additions & 3 deletions src/gsumm.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ SEXP gmean(SEXP x, SEXP narmArg)
} else {
// narm==true and anyNA==true
int *restrict nna_counts = calloc(ngrp, sizeof(int));
if (!nna_counts) error(_("Unable to allocate %d * %lu bytes for non-NA counts in gmean na.rm=TRUE"), ngrp, sizeof(int));
if (!nna_counts) error(_("Unable to allocate %d * %zu bytes for non-NA counts in gmean na.rm=TRUE"), ngrp, sizeof(int));
#pragma omp parallel for num_threads(getDTthreads(highSize, false))
for (int h=0; h<highSize; h++) {
double *restrict _ans = ansp + (h<<bitshift);
Expand Down Expand Up @@ -673,7 +673,7 @@ SEXP gmean(SEXP x, SEXP narmArg)
// # nocov start
free(nna_counts_r); // free(NULL) is allowed and does nothing. Avoids repeating the error() call here.
free(nna_counts_i);
error(_("Unable to allocate %d * %lu bytes for non-NA counts in gmean na.rm=TRUE"), ngrp, sizeof(int));
error(_("Unable to allocate %d * %zu bytes for non-NA counts in gmean na.rm=TRUE"), ngrp, sizeof(int));
// # nocov end
}
#pragma omp parallel for num_threads(getDTthreads(highSize, false))
Expand Down Expand Up @@ -1116,7 +1116,7 @@ SEXP gprod(SEXP x, SEXP narmArg) {
//clock_t start = clock();
if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gprod");
long double *s = malloc(ngrp * sizeof(long double));
if (!s) error(_("Unable to allocate %d * %lu bytes for gprod"), ngrp, sizeof(long double));
if (!s) error(_("Unable to allocate %d * %zu bytes for gprod"), ngrp, sizeof(long double));
for (int i=0; i<ngrp; ++i) s[i] = 1.0;
switch(TYPEOF(x)) {
case LGLSXP: case INTSXP: {
Expand Down
24 changes: 12 additions & 12 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,19 @@ void attribute_visible R_init_data_table(DllInfo *info)
const char *msg = _("... failed. Please forward this message to maintainer('data.table').");
if ((int)NA_INTEGER != (int)INT_MIN) error(_("Checking NA_INTEGER [%d] == INT_MIN [%d] %s"), NA_INTEGER, INT_MIN, msg);
if ((int)NA_INTEGER != (int)NA_LOGICAL) error(_("Checking NA_INTEGER [%d] == NA_LOGICAL [%d] %s"), NA_INTEGER, NA_LOGICAL, msg);
if (sizeof(int) != 4) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int", sizeof(int), 4, msg);
if (sizeof(double) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "double", sizeof(double), 8, msg); // 8 on both 32bit and 64bit
if (sizeof(int) != 4) error(_("Checking sizeof(%s) [%zu] is %d %s"), "int", sizeof(int), 4, msg);
if (sizeof(double) != 8) error(_("Checking sizeof(%s) [%zu] is %d %s"), "double", sizeof(double), 8, msg); // 8 on both 32bit and 64bit
// alignof not available in C99: if (alignof(double) != 8) error(_("Checking alignof(double) [%lu] is 8 %s"), alignof(double), msg); // 8 on both 32bit and 64bit
if (sizeof(long long) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "long long", sizeof(long long), 8, msg);
if (sizeof(char *) != 4 && sizeof(char *) != 8) error(_("Checking sizeof(pointer) [%lu] is 4 or 8 %s"), sizeof(char *), msg);
if (sizeof(SEXP) != sizeof(char *)) error(_("Checking sizeof(SEXP) [%lu] == sizeof(pointer) [%lu] %s"), sizeof(SEXP), sizeof(char *), msg);
if (sizeof(uint64_t) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint64_t", sizeof(uint64_t), 8, msg);
if (sizeof(int64_t) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int64_t", sizeof(int64_t), 8, msg);
if (sizeof(signed char) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "signed char", sizeof(signed char), 1, msg);
if (sizeof(int8_t) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int8_t", sizeof(int8_t), 1, msg);
if (sizeof(uint8_t) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint8_t", sizeof(uint8_t), 1, msg);
if (sizeof(int16_t) != 2) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int16_t", sizeof(int16_t), 2, msg);
if (sizeof(uint16_t) != 2) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint16_t", sizeof(uint16_t), 2 ,msg);
if (sizeof(long long) != 8) error(_("Checking sizeof(%s) [%zu] is %d %s"), "long long", sizeof(long long), 8, msg);
if (sizeof(char *) != 4 && sizeof(char *) != 8) error(_("Checking sizeof(pointer) [%zu] is 4 or 8 %s"), sizeof(char *), msg);
if (sizeof(SEXP) != sizeof(char *)) error(_("Checking sizeof(SEXP) [%zu] == sizeof(pointer) [%zu] %s"), sizeof(SEXP), sizeof(char *), msg);
if (sizeof(uint64_t) != 8) error(_("Checking sizeof(%s) [%zu] is %d %s"), "uint64_t", sizeof(uint64_t), 8, msg);
if (sizeof(int64_t) != 8) error(_("Checking sizeof(%s) [%zu] is %d %s"), "int64_t", sizeof(int64_t), 8, msg);
if (sizeof(signed char) != 1) error(_("Checking sizeof(%s) [%zu] is %d %s"), "signed char", sizeof(signed char), 1, msg);
if (sizeof(int8_t) != 1) error(_("Checking sizeof(%s) [%zu] is %d %s"), "int8_t", sizeof(int8_t), 1, msg);
if (sizeof(uint8_t) != 1) error(_("Checking sizeof(%s) [%zu] is %d %s"), "uint8_t", sizeof(uint8_t), 1, msg);
if (sizeof(int16_t) != 2) error(_("Checking sizeof(%s) [%zu] is %d %s"), "int16_t", sizeof(int16_t), 2, msg);
if (sizeof(uint16_t) != 2) error(_("Checking sizeof(%s) [%zu] is %d %s"), "uint16_t", sizeof(uint16_t), 2 ,msg);

SEXP tmp = PROTECT(allocVector(INTSXP,2));
if (LENGTH(tmp)!=2) error(_("Checking LENGTH(allocVector(INTSXP,2)) [%d] is 2 %s"), LENGTH(tmp), msg);
Expand Down

0 comments on commit 3535631

Please sign in to comment.