Message ID | 20220803173211.14292-1-pvorel@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/1] aiodio: Fix format string for 32bit | expand |
Hi! > On 32bit char pointer is int and size_t is unsigned int, > Cast to long / unsigned long. Actually char pointer is char pointer, that is not an integer type at all. If you do a pointer difference you end up with an signed integer value of ptrdiff_t type, because unlike the result of sizeof(foo) pointer difference can be negative as well. In C99 ptrdiff_t can be printed as %td see the "Length modifier" part of man 3 printf.
diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h index d9cbd8611..283f7f5db 100644 --- a/testcases/kernel/io/ltp-aiodio/common.h +++ b/testcases/kernel/io/ltp-aiodio/common.h @@ -19,7 +19,7 @@ static inline char *check_zero(char *buf, int size) if (*buf != 0) { tst_res(TINFO, "non zero buffer at buf[%lu] => 0x%02x,%02x,%02x,%02x", - buf - p, (unsigned int)buf[0], + (long)(buf - p), (unsigned int)buf[0], size > 1 ? (unsigned int)buf[1] : 0, size > 2 ? (unsigned int)buf[2] : 0, size > 3 ? (unsigned int)buf[3] : 0); @@ -78,8 +78,8 @@ static inline void io_read(const char *filename, int filesize, volatile int *run if (r > 0) { bufoff = check_zero(buff, r); if (bufoff) { - tst_res(TINFO, "non-zero read at offset %zu", - offset + (bufoff - buff)); + tst_res(TINFO, "non-zero read at offset %lu", + (long int)offset + (bufoff - buff)); break; } offset += r;
On 32bit char pointer is int and size_t is unsigned int, Cast to long / unsigned long. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- Hi, IMHO %zu is C99, we don't define -std and my gcc 12 uses by default -std=gnu17. Therefore I'm surprised that %zu does not work. Based on Andrea patch: https://patchwork.ozlabs.org/project/ltp/patch/20220803120905.3107-1-andrea.cervesato@suse.com/ Kind regards, Petr testcases/kernel/io/ltp-aiodio/common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)