From 14223b14e23d98aff209b6514abc042046cf7837 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 6 Dec 2023 09:55:22 +0800 Subject: [PATCH 1/3] Fix two "unusual" format warnings (#5792) * Fix two "unusual" format warnings * Add comment, find more %d usages * Update src/assign.c --------- Co-authored-by: jangorecki --- src/assign.c | 2 +- src/fread.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/assign.c b/src/assign.c index 513dc3a320..151c57c282 100644 --- a/src/assign.c +++ b/src/assign.c @@ -468,7 +468,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) // strong error message for now. else if (TRUELENGTH(names) != oldtncol) // Use (long long) to cast R_xlen_t to a fixed type to robustly avoid -Wformat compiler warnings, see #5768, PRId64 didnt work - error(_("Internal error: selfrefnames is ok but tl names [%ld] != tl [%d]"), TRUELENGTH(names), oldtncol); // # nocov + error(_("Internal error: selfrefnames is ok but tl names [%lld] != tl [%d]"), (long long)TRUELENGTH(names), oldtncol); // # nocov SETLENGTH(dt, oldncol+LENGTH(newcolnames)); SETLENGTH(names, oldncol+LENGTH(newcolnames)); for (i=0; i Date: Wed, 6 Dec 2023 10:48:36 +0800 Subject: [PATCH 2/3] fix --- src/assign.c | 2 +- src/gsumm.c | 2 +- src/init.c | 26 +++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/assign.c b/src/assign.c index 151c57c282..dc5c01d560 100644 --- a/src/assign.c +++ b/src/assign.c @@ -792,7 +792,7 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con // # nocov start for (int k=0; k8) error(_("Pointers are %lu bytes, greater than 8. We have not tested on any architecture greater than 64bit yet."), sizeof(char *)); + if (sizeof(char *)>8) error(_("Pointers are %zu bytes, greater than 8. We have not tested on any architecture greater than 64bit yet."), sizeof(char *)); // One place we need the largest sizeof is the working memory malloc in reorder.c } @@ -165,19 +165,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(int) [%lu] is 4 %s"), sizeof(int), msg); - if (sizeof(double) != 8) error(_("Checking sizeof(double) [%lu] is 8 %s"), sizeof(double), msg); // 8 on both 32bit and 64bit + if (sizeof(int) != 4) error(_("Checking sizeof(int) [%zu] is 4 %s"), sizeof(int), msg); + if (sizeof(double) != 8) error(_("Checking sizeof(double) [%zu] is 8 %s"), sizeof(double), msg); // 8 on both 32bit and 64bit // alignof not available in C99: if (alignof(double) != 8) error(_("Checking alignof(double) [%d] is 8 %s"), alignof(double), msg); // 8 on both 32bit and 64bit - if (sizeof(long long) != 8) error(_("Checking sizeof(long long) [%lu] is 8 %s"), sizeof(long long), 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(uint64_t) [%lu] is 8 %s"), sizeof(uint64_t), msg); - if (sizeof(int64_t) != 8) error(_("Checking sizeof(int64_t) [%lu] is 8 %s"), sizeof(int64_t), msg); - if (sizeof(signed char) != 1) error(_("Checking sizeof(signed char) [%lu] is 1 %s"), sizeof(signed char), msg); - if (sizeof(int8_t) != 1) error(_("Checking sizeof(int8_t) [%lu] is 1 %s"), sizeof(int8_t), msg); - if (sizeof(uint8_t) != 1) error(_("Checking sizeof(uint8_t) [%lu] is 1 %s"), sizeof(uint8_t), msg); - if (sizeof(int16_t) != 2) error(_("Checking sizeof(int16_t) [%lu] is 2 %s"), sizeof(int16_t), msg); - if (sizeof(uint16_t) != 2) error(_("Checking sizeof(uint16_t) [%lu] is 2 %s"), sizeof(uint16_t), msg); + if (sizeof(long long) != 8) error(_("Checking sizeof(long long) [%zu] is 8 %s"), sizeof(long long), 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(uint64_t) [%zu] is 8 %s"), sizeof(uint64_t), msg); + if (sizeof(int64_t) != 8) error(_("Checking sizeof(int64_t) [%zu] is 8 %s"), sizeof(int64_t), msg); + if (sizeof(signed char) != 1) error(_("Checking sizeof(signed char) [%zu] is 1 %s"), sizeof(signed char), msg); + if (sizeof(int8_t) != 1) error(_("Checking sizeof(int8_t) [%zu] is 1 %s"), sizeof(int8_t), msg); + if (sizeof(uint8_t) != 1) error(_("Checking sizeof(uint8_t) [%zu] is 1 %s"), sizeof(uint8_t), msg); + if (sizeof(int16_t) != 2) error(_("Checking sizeof(int16_t) [%zu] is 2 %s"), sizeof(int16_t), msg); + if (sizeof(uint16_t) != 2) error(_("Checking sizeof(uint16_t) [%zu] is 2 %s"), sizeof(uint16_t), msg); SEXP tmp = PROTECT(allocVector(INTSXP,2)); if (LENGTH(tmp)!=2) error(_("Checking LENGTH(allocVector(INTSXP,2)) [%d] is 2 %s"), LENGTH(tmp), msg); From 7a910656aa394ce6476444bbd5833f3aef9ef91b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 6 Dec 2023 02:58:39 +0000 Subject: [PATCH 3/3] more %zu in gsumm --- src/gsumm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gsumm.c b/src/gsumm.c index b290046d8f..93121eb7f4 100644 --- a/src/gsumm.c +++ b/src/gsumm.c @@ -606,10 +606,10 @@ SEXP gmean(SEXP x, SEXP narm) if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gsum"); long double *s = calloc(ngrp, sizeof(long double)), *si=NULL; // s = sum; si = sum imaginary just for complex - if (!s) error(_("Unable to allocate %d * %lu bytes for sum in gmean na.rm=TRUE"), ngrp, sizeof(long double)); + if (!s) error(_("Unable to allocate %d * %zu bytes for sum in gmean na.rm=TRUE"), ngrp, sizeof(long double)); int *c = calloc(ngrp, sizeof(int)); - if (!c) error(_("Unable to allocate %d * %lu bytes for counts in gmean na.rm=TRUE"), ngrp, sizeof(int)); + if (!c) error(_("Unable to allocate %d * %zu bytes for counts in gmean na.rm=TRUE"), ngrp, sizeof(int)); switch(TYPEOF(x)) { case LGLSXP: case INTSXP: { @@ -635,7 +635,7 @@ SEXP gmean(SEXP x, SEXP narm) case CPLXSXP: { const Rcomplex *xd = COMPLEX(x); si = calloc(ngrp, sizeof(long double)); - if (!si) error(_("Unable to allocate %d * %lu bytes for si in gmean na.rm=TRUE"), ngrp, sizeof(long double)); + if (!si) error(_("Unable to allocate %d * %zu bytes for si in gmean na.rm=TRUE"), ngrp, sizeof(long double)); for (int i=0; i