From ac5b12440da75a36fa7d98a32545acf1e696004f Mon Sep 17 00:00:00 2001 From: sebastienr Date: Tue, 9 Nov 2021 09:53:48 +0100 Subject: fix -Wformat issues reported by clang (#349) * some previous dlt_vlog was using %lu specifier to display an uint64_t variable. However, this isn't portable as depending on the system you're targeting (32bits, 64bits, Linux, android, etc.), the uint64_t can be an unsigned long long. This prevents compilation on system where -Werror and -Wformat is activated coupled with a less tolerant compiler (e.g clang). Instead, PRIxN macros (e.g PRIu64 for uint64_t) are now used as specifier to ensure compatibility for each platforms * for bytes_read which is of type ssize_t, zd specifier is used as indicated in C99 standard * for st_size (from struct stat) which is of type off_t, POSIX says that it should be a signed integer. To be safe, we now use %jd specifier to ensure that it will fit correctly --- src/shared/dlt_common.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/shared/dlt_common.c') diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index de65201..e964d1b 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -1488,7 +1488,7 @@ DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose) if (verbose) /* print file length */ - dlt_vlog(LOG_DEBUG, "File is %lu bytes long\n", file->file_length); + dlt_vlog(LOG_DEBUG, "File is %" PRIu64 "bytes long\n", file->file_length); return DLT_RETURN_OK; } @@ -1521,14 +1521,14 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */ if (0 != fseek(file->handle, file->file_position, SEEK_SET)) { - dlt_vlog(LOG_WARNING, "Seek failed to file_position %lu\n", + dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 "\n", file->file_position); return DLT_RETURN_ERROR; } /* get file position at start of DLT message */ if (verbose) - dlt_vlog(LOG_INFO, "Position in file: %lu\n", file->file_position); + dlt_vlog(LOG_INFO, "Position in file: %" PRIu64 "\n", file->file_position); /* read header */ if (dlt_file_read_header(file, verbose) < DLT_RETURN_OK) { @@ -1639,7 +1639,7 @@ DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose) /* get file position at start of DLT message */ if (verbose) - dlt_vlog(LOG_DEBUG, "Position in file: %lu\n", file->file_position); + dlt_vlog(LOG_DEBUG, "Position in file: %" PRIu64 "\n", file->file_position); /* read header */ if (dlt_file_read_header_raw(file, resync, verbose) < DLT_RETURN_OK) { @@ -4148,7 +4148,7 @@ DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, while (ret >= DLT_RETURN_OK && file->file_position < file->file_length) { /* get file position at start of DLT message */ if (verbose) - dlt_vlog(LOG_DEBUG, "Position in file: %lu\n", file->file_position); + dlt_vlog(LOG_DEBUG, "Position in file: %" PRIu64 "\n", file->file_position); /* read all header and payload */ ret = dlt_file_read_header(file, verbose); -- cgit v1.2.1