[Bug 2033113] Re: Math error in libbsd timespecsub

Reggie McMurtrey 2033113 at bugs.launchpad.net
Fri Aug 25 23:14:55 UTC 2023


Ok, I see what you are doing and why, but it may be worth putting a blurb
in the timespecsub man page about how you are handling negative numbers.
I'm fighting another bug in a system where we aren't meeting our deadline
(why we are gettiing negative sleep #'s).  we added some debug code to see
what our sleep values were and the values didn't make sense.

On Fri, Aug 25, 2023 at 5:30 PM Thorsten Glaser <2033113 at bugs.launchpad.net>
wrote:

> No, the code is correct.
>
> If you calculate (for the sake of simplicity I’m skipping the 0s) 0.1 -
> 0.2 you get -0.1 which in timespec is the same as -1 + .9.
>
> If you’re trying to calculate how long to sleep for, you probably
> shouldn’t sleep *at all* if your destination timestamp is already in the
> past.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/2033113
>
> Title:
>   Math error in libbsd timespecsub
>
> Status in libbsd package in Ubuntu:
>   New
>
> Bug description:
>   #define timespecsub(tsp, usp, vsp)                                      \
>           do {                                                            \
>                   (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
>                   (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
>                   if ((vsp)->tv_nsec < 0) {                               \
>                           (vsp)->tv_sec--;                                \
>                           (vsp)->tv_nsec += 1000000000L;                  \
>                   }                                                       \
>           } while (0)
>   #endif
>   *******************************************
>   the line
>
>   "if ((vsp)->tv_nsec < 0) {"
>
>   should be
>
>   "if ((vsp)->tv_nsec < 0 && (vsp)->tv_sec != 0) {"
>
>   try tsp.tv_sec = 0, tsp.tv_nsec = 1, usp.tv_sec = 0, usp.tv_nsec = 2
>   as a test case
>
>   I found this trying to calculate how long to nanosleep for.
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+source/libbsd/+bug/2033113/+subscriptions
>
>

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to libbsd in Ubuntu.
https://bugs.launchpad.net/bugs/2033113

Title:
  Math error in libbsd timespecsub

Status in libbsd package in Ubuntu:
  New

Bug description:
  #define timespecsub(tsp, usp, vsp)                                      \
          do {                                                            \
                  (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
                  (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
                  if ((vsp)->tv_nsec < 0) {                               \
                          (vsp)->tv_sec--;                                \
                          (vsp)->tv_nsec += 1000000000L;                  \
                  }                                                       \
          } while (0)
  #endif
  *******************************************
  the line 

  "if ((vsp)->tv_nsec < 0) {"

  should be

  "if ((vsp)->tv_nsec < 0 && (vsp)->tv_sec != 0) {"

  try tsp.tv_sec = 0, tsp.tv_nsec = 1, usp.tv_sec = 0, usp.tv_nsec = 2
  as a test case

  I found this trying to calculate how long to nanosleep for.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/libbsd/+bug/2033113/+subscriptions




More information about the foundations-bugs mailing list