Message ID | 20221215131028.12797-1-hyyoxhk@163.com |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | [v1,1/1] Fix printf format warnings under 32-bit compilers | expand |
> - use `PRIuPTR` instead of "%lu" for formatting size_t values > - use `SCNu64` instead of "%lu" for formatting dev_t values > - use `PRId64` instead of "%ld" for formatting uint64_t values > - use `CURL_FORMAT_CURL_OFF_TU` instead of "%lu" for formatting curl_off_t values > Solves the following warning: > core/cpio_utils.c: In function ‘copy_write’: > include/util.h:92:41: warning: format ‘%lu’ expects argument of type ‘long unsigned int’ > but argument 7 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] > 92 | "ERROR %s : %s : %d : " format, \ > | ^~~~~~~~~~~~~~~~~~~~~~~ > include/util.h:110:9: note: in expansion of macro ‘swupdate_notify’ > 110 | swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg) > | ^~~~~~~~~~~~~~~ > core/cpio_utils.c:141:25: note: in expansion of macro ‘ERROR’ > 141 | ERROR("cannot write %lu bytes: %s", len, strerror(errno)); > | ^~~~~ > include/util.h:99:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’ > but argument 4 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] > 99 | "ERROR : " format, ## arg); \ > ... > include/util.h:103:41: warning: format ‘%ld’ expects argument of type ‘long int’ > but argument 5 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=] > 103 | "[%s] : " format, __func__, ## arg); \ > | ^~~~~~~~~ > include/util.h:110:9: note: in expansion of macro ‘swupdate_notify’ > 110 | swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg) > | ^~~~~~~~~~~~~~~ > mongoose/mongoose_interface.c:538:17: note: in expansion of macro ‘ERROR’ > 538 | ERROR("Connection lost, no data for %ld seconds, closing..." > Signed-off-by: He Yong <hyyoxhk@163.com> Applied to swupdate, master, thanks ! Best regards, Stefano Babic
diff --git a/core/cpio_utils.c b/core/cpio_utils.c index a31f254..489a12c 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -7,6 +7,7 @@ #include <stdbool.h> #include <stdlib.h> +#include <inttypes.h> #include <stdio.h> #include <unistd.h> #include <errno.h> @@ -138,12 +139,12 @@ int copy_write(void *out, const void *buf, size_t len) if (ret < 0) { if (errno == EINTR) continue; - ERROR("cannot write %lu bytes: %s", len, strerror(errno)); + ERROR("cannot write %" PRIuPTR " bytes: %s", len, strerror(errno)); return -1; } if (ret == 0) { - ERROR("cannot write %lu bytes: %s", len, strerror(errno)); + ERROR("cannot write %" PRIuPTR " bytes: %s", len, strerror(errno)); return -1; } diff --git a/core/notifier.c b/core/notifier.c index 87acb01..2ff2013 100644 --- a/core/notifier.c +++ b/core/notifier.c @@ -7,6 +7,7 @@ #include <stdio.h> #include <stdlib.h> +#include <inttypes.h> #include <string.h> #include <unistd.h> #include <errno.h> @@ -492,7 +493,7 @@ void notify_init(void) if (sd_booted() && getenv("JOURNAL_STREAM") != NULL) { dev_t device; ino_t inode; - if (sscanf(getenv("JOURNAL_STREAM"), "%lu:%lu", &device, &inode) == 2) { + if (sscanf(getenv("JOURNAL_STREAM"), "%" SCNu64 ":%lu", &device, &inode) == 2) { struct stat statbuffer; if (fstat(fileno(stderr), &statbuffer) == 0) { if (inode == statbuffer.st_ino && device == statbuffer.st_dev) { diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 81808f8..0435f15 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -1171,7 +1171,7 @@ channel_op_res_t channel_get_file(channel_t *this, void *data) WARN("Failed to get total download size for URL %s.", channel_data->url); } else - INFO("Total download size is %lu kB.", + INFO("Total download size is %" CURL_FORMAT_CURL_OFF_TU " kB.", download_data.total_download_size / 1024); } diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 71c394f..a17d9bd 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -535,7 +535,7 @@ static void timer_ev_handler(void *fn_data) if (fus && (watchdog_conn > 0) && (mg_millis() - fus->last_io_time > (watchdog_conn * 1000))) { /* Connection lost, drop data */ - ERROR("Connection lost, no data for %ld seconds, closing...", + ERROR("Connection lost, no data for %" PRId64 " seconds, closing...", (mg_millis() - fus->last_io_time) / 1000); mg_http_reply(fus->c, 408, "", "%s", "Request Timeout\n"); fus->c->is_draining = 1;
- use `PRIuPTR` instead of "%lu" for formatting size_t values - use `SCNu64` instead of "%lu" for formatting dev_t values - use `PRId64` instead of "%ld" for formatting uint64_t values - use `CURL_FORMAT_CURL_OFF_TU` instead of "%lu" for formatting curl_off_t values Solves the following warning: core/cpio_utils.c: In function ‘copy_write’: include/util.h:92:41: warning: format ‘%lu’ expects argument of type ‘long unsigned int’ but argument 7 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] 92 | "ERROR %s : %s : %d : " format, \ | ^~~~~~~~~~~~~~~~~~~~~~~ include/util.h:110:9: note: in expansion of macro ‘swupdate_notify’ 110 | swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg) | ^~~~~~~~~~~~~~~ core/cpio_utils.c:141:25: note: in expansion of macro ‘ERROR’ 141 | ERROR("cannot write %lu bytes: %s", len, strerror(errno)); | ^~~~~ include/util.h:99:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’ but argument 4 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] 99 | "ERROR : " format, ## arg); \ ... include/util.h:103:41: warning: format ‘%ld’ expects argument of type ‘long int’ but argument 5 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=] 103 | "[%s] : " format, __func__, ## arg); \ | ^~~~~~~~~ include/util.h:110:9: note: in expansion of macro ‘swupdate_notify’ 110 | swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg) | ^~~~~~~~~~~~~~~ mongoose/mongoose_interface.c:538:17: note: in expansion of macro ‘ERROR’ 538 | ERROR("Connection lost, no data for %ld seconds, closing..." Signed-off-by: He Yong <hyyoxhk@163.com> --- core/cpio_utils.c | 5 +++-- core/notifier.c | 3 ++- corelib/channel_curl.c | 2 +- mongoose/mongoose_interface.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)