Skip to content

Commit

Permalink
Avoid warning on 32bit
Browse files Browse the repository at this point in the history
On 32bit arches where time_t is defined as long int and where
sizeof(long)==sizeof(int), PRI_TIME is PRIu32 which is "u" and gcc warns about
ignoring the long part of the integer type. There is no problem besides the
warning.

Use "lu" in the above conditions and PRIu32 in all other 32bit time_t cases.

udevadm-monitor.c: In function ‘print_device’:
udevadm-monitor.c:49:16: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__time_t’ {aka ‘long int’} [-Wformat=]
   49 |         printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
      |                ^~~~~~~~
   50 |                source,
   51 |                ts.tv_sec, ts.tv_nsec/1000,
      |                ~~~~~~~~~
      |                  |
      |                  __time_t {aka long int}
In file included from ../../src/shared/macro.h:26,
                 from udev.h:26,
                 from udevadm-monitor.c:35:
/usr/include/inttypes.h:104:19: note: format string is defined here
  104 | # define PRIu32  "u"
  • Loading branch information
bbonev committed Jun 10, 2022
1 parent dd6b068 commit b1de2b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ AC_CHECK_SIZEOF(pid_t)
AC_CHECK_SIZEOF(uid_t)
AC_CHECK_SIZEOF(gid_t)
AC_CHECK_SIZEOF(dev_t)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(time_t)
AC_CHECK_SIZEOF(rlim_t,,[[
#include <sys/time.h>
Expand Down
6 changes: 5 additions & 1 deletion src/shared/formats-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
#if SIZEOF_TIME_T == 8
# define PRI_TIME PRIi64
#elif SIZEOF_TIME_T == 4
# define PRI_TIME PRIu32
# if SIZEOF_LONG == 4
# define PRI_TIME "lu"
# else
# define PRI_TIME PRIu32
# endif
#else
# error Unknown time_t size
#endif
Expand Down

0 comments on commit b1de2b7

Please sign in to comment.