From e13bf55d0e6906eb7b79517c75e2f394949745ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sun, 6 Dec 2015 18:06:08 +0100 Subject: [PATCH] Use PRIdMAX instead of %jd formatting string Some toolchains (on Windows) still does support POSIX %jd formatting string. Use ISOC99 PRIdMAX instead. Reported-by: Martin Doucha --- client/common.c | 5 +++-- src/isds.c | 3 ++- test/offline/isds-eventstring2event.c | 2 +- test/offline/isds-timestring2timeval.c | 3 ++- test/simline/service.c | 3 ++- test/test.c | 5 +++-- test/test.h | 3 ++- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/common.c b/client/common.c index 6905302..797a048 100644 --- a/client/common.c +++ b/client/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -387,7 +388,7 @@ void print_timeval(const struct timeval *time) { if (!localtime_r(&(time->tv_sec), &broken)) goto error; if (!strftime(buffer, sizeof(buffer)/sizeof(char), "%c", &broken)) goto error; - printf("%s, %jd us\n", buffer, (intmax_t)time->tv_usec); + printf("%s, %" PRIdMAX " us\n", buffer, (intmax_t)time->tv_usec); return; error: @@ -723,7 +724,7 @@ int mmap_file(const char *file, int *fd, void **buffer, size_t *length) { return -1; } if (file_info.st_size < 0) { - fprintf(stderr, "File `%s' has negative size: %jd\n", file, + fprintf(stderr, "File `%s' has negative size: %" PRIdMAX "\n", file, (intmax_t) file_info.st_size); close(*fd); return -1; diff --git a/src/isds.c b/src/isds.c index 726ac58..c8f4ff4 100644 --- a/src/isds.c +++ b/src/isds.c @@ -6,6 +6,7 @@ #include #include /* For uint8_t and intmax_t */ #include /* Because of LONG_{MIN,MAX} constants */ +#include /* For PRIdMAX formatting macro */ #include "utils.h" #if HAVE_LIBCURL #include "soap.h" @@ -2235,7 +2236,7 @@ static isds_error timeval2timestring(const struct timeval *time, * integer to accomodate values from range [-1, 1000000]. * See */ if (-1 == isds_asprintf((char **) string, - "%04d-%02d-%02dT%02d:%02d:%02d.%06jd", + "%04d-%02d-%02dT%02d:%02d:%02d.%06" PRIdMAX, broken.tm_year + 1900, broken.tm_mon + 1, broken.tm_mday, broken.tm_hour, broken.tm_min, broken.tm_sec, (intmax_t)time->tv_usec)) diff --git a/test/offline/isds-eventstring2event.c b/test/offline/isds-eventstring2event.c index 08d5f05..d606d93 100644 --- a/test/offline/isds-eventstring2event.c +++ b/test/offline/isds-eventstring2event.c @@ -26,7 +26,7 @@ static int test_eventstring2event(const xmlChar *string, isds_error error, correct_event->time->tv_sec, new_event->time->tv_sec); if (correct_event->time->tv_usec != new_event->time->tv_usec) FAIL_TEST("Returned event time differs in tv_usec: " - "expected=%jd, got=%jd", + "expected=%" PRIdMAX ", got=%" PRIdMAX, (intmax_t)correct_event->time->tv_usec, (intmax_t)new_event->time->tv_usec); } diff --git a/test/offline/isds-timestring2timeval.c b/test/offline/isds-timestring2timeval.c index c7867ca..080d4e3 100644 --- a/test/offline/isds-timestring2timeval.c +++ b/test/offline/isds-timestring2timeval.c @@ -34,7 +34,8 @@ static int test_timestring2timeval(const xmlChar *time, const isds_error error, FAIL_TEST("Returned struct timeval differs in tv_sec: expected=%d, got=%d", correct_timeval->tv_sec, (*new_timeval)->tv_sec); if (correct_timeval->tv_usec != (*new_timeval)->tv_usec) - FAIL_TEST("Returned struct timeval differs in tv_usec: expected=%jd, got=%jd", + FAIL_TEST("Returned struct timeval differs in tv_usec: expected=%" PRIdMAX + ", got=%" PRIdMAX, (intmax_t)correct_timeval->tv_usec, (intmax_t)(*new_timeval)->tv_usec); diff --git a/test/simline/service.c b/test/simline/service.c index 6d48a54..644ba0e 100644 --- a/test/simline/service.c +++ b/test/simline/service.c @@ -6,6 +6,7 @@ #include "system.h" #include #include /* For intmax_t */ +#include /* For PRIdMAX */ #include #include #include @@ -599,7 +600,7 @@ static http_error timeval2timestring(const struct timeval *time, * integer to accomodate values from range [-1, 1000000]. * See */ if (-1 == test_asprintf(string, - "%04d-%02d-%02dT%02d:%02d:%02d.%06jd", + "%04d-%02d-%02dT%02d:%02d:%02d.%06" PRIdMAX, broken.tm_year + 1900, broken.tm_mon + 1, broken.tm_mday, broken.tm_hour, broken.tm_min, broken.tm_sec, (intmax_t)time->tv_usec)) diff --git a/test/test.c b/test/test.c index 542ce87..3b71a6f 100644 --- a/test/test.c +++ b/test/test.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,7 @@ int test_mmap_file(const char *file, int *fd, void **buffer, size_t *length) { return -1; } if (file_info.st_size < 0) { - fprintf(stderr, "File `%s' has negative size: %jd\n", file, + fprintf(stderr, "File `%s' has negative size: %" PRIdMAX "\n", file, (intmax_t) file_info.st_size); close(*fd); return -1; @@ -166,7 +167,7 @@ int test_mmap_file(const char *file, int *fd, void **buffer, size_t *length) { return -1; } if (file_info.st_size < 0) { - fprintf(stderr, "File `%s' has negative size: %jd\n", file, + fprintf(stderr, "File `%s' has negative size: %" PRIdMAX "\n", file, (intmax_t) file_info.st_size); close(*fd); return -1; diff --git a/test/test.h b/test/test.h index d361a04..e04ce4b 100644 --- a/test/test.h +++ b/test/test.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -155,7 +156,7 @@ void *test_destructor_argument; "expected=%d, got=%d", (x)->tv_sec, (y)->tv_sec); \ if ((x)->tv_usec != (y)->tv_usec) \ FAIL_TEST("struct timeval * differs in tv_usec: " \ - "expected=%jd, got=%jd", (intmax_t)(x)->tv_usec, \ + "expected=%" PRIdMAX ", got=%" PRIdMAX, (intmax_t)(x)->tv_usec, \ (intmax_t)(y)->tv_usec); \ } \ } -- 2.11.4.GIT