NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/53595: getitimer() returns strange value



The following reply was made to PR kern/53595; it has been noted by GNATS.

From: christos%zoulas.com@localhost (Christos Zoulas)
To: gnats-bugs%NetBSD.org@localhost, kern-bug-people%netbsd.org@localhost, 
	gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/53595: getitimer() returns strange value
Date: Tue, 11 Sep 2018 22:48:00 -0400

 On Sep 12, 12:05am, ohnoya%lilac.plala.or.jp@localhost (ohnoya%lilac.plala.or.jp@localhost) wrote:
 -- Subject: kern/53595: getitimer() returns strange value
 
 | #include <stdio.h>
 | #include <signal.h>
 | #include <unistd.h>
 | #include <sys/time.h>
 | 
 | int main(int argc, char** argv) {
 |         struct itimerval  interval, remain;
 | 
 |         interval.it_value.tv_usec = 250000;
 |         interval.it_value.tv_sec = 0;
 |         interval.it_interval.tv_usec = 250000;
 |         interval.it_interval.tv_sec = 0;
 | 
 |         setitimer(ITIMER_REAL, &interval, NULL);
 | 
 |         getitimer(ITIMER_REAL, &remain);
 |         printf("getitimer : it_value.tv_usec:%lu, it_value.tv_sec:%lu, it_interval.tv_usec:%lu, it_interval.tv_sec:%lu\n",
 |                 remain.it_value.tv_usec, remain.it_value.tv_sec, remain.it_interval.tv_usec, remain.it_interval.tv_sec);
 | 
 |         return 0;
 | }
 | ---
 | getitimer : it_value.tv_usec:250000, it_value.tv_sec:0, it_interval.tv_usec:0, it_interval.tv_sec:250000
 
 The program is broken. time_t (tv_sec) is int64_t on NetBSD and tv_usec
 (suseconds_t) is an int32_t.
 1. the long format is wrong for LP64 and tv_usec
 2. the long format is wrong for ILP32 and tv_sec
 
 If you compile with -Wall, you'll see the format warnings. The program
 prints the right values if you:
 
         printf("getitimer : it_value.tv_usec:%jd, it_value.tv_sec:%jd, "
             "it_interval.tv_usec:%jd, it_interval.tv_sec:%jd\n",
             (intmax_t)remain.it_value.tv_usec,
             (intmax_t)remain.it_value.tv_sec,
             (intmax_t)remain.it_interval.tv_usec,
             (intmax_t)remain.it_interval.tv_sec);
 


Home | Main Index | Thread Index | Old Index