Skip to content
Snippets Groups Projects
Commit f587a43e authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

When a double is cast to an int, but the double has a larger value

than the int supports, it's set to 0x80000000 to indicate overflow.

msclock() is *always* overflowing, and clock_t is only 32-bits on
some platforms (specifically FreeBSD).  To "avoid" problems, just
keep subtracting UIN32_MAX from the value until it's less than INT_MAX
then cast.

This function is, of course, terrible and shouldn't actually be used,
but it should at least sorta kinda workish.
parent 74729f19
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2710 passed
......@@ -696,7 +696,14 @@ char* os_cmdshell(void)
#ifdef __unix__
clock_t msclock(void)
{
return (clock_t)(xp_timer() * 1000);
long double t = roundl(xp_timer() * 1000);
if (sizeof(clock_t) < 8) {
while (t > INT32_MAX)
t -= UINT32_MAX;
}
return (clock_t)t;
}
#endif
......
  • Owner

    From the Linux man page on roundl(): If you want to store the rounded value in an integer type, you probably want to use one of the functions described in lround(3) instead.

  • Author Maintainer

    Can't because it's too big to fit... we don't want to deal with FP exceptions.

  • Owner

    Interesting. So were you seeing msclock() always returning the same number before?

  • Author Maintainer

    Yep.

  • Owner

    And this is because we're now greater than some magic number of milliseconds away from the Epoch?

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment