-2

Which value will be returned if possible clock_t (aka signed long) range will be overflowed?

Let's assume that I use kernel 2.6 version and arch is x86 (32 bits). sizeof(signed long) = 4 bytes. Max value = 2147483647.

According to man page - here, syscall times() returns the number of clock ticks that have elapsed since an arbitrary point in the past.

In "Notes" section mentioned following: "On Linux, the "arbitrary point in the past" from which the return value of times() is measured has varied across kernel versions. Since Linux 2.6, this point is (2^32/HZ) - 300 seconds before system boot time".

So, I don't understand what value in decimal representation will be start point (suppose HZ = 100). And what return value will be after overflowing.

  • What I understand is that there is an overflow just some minutes after boot time in Linux>2.6, I suppose this to maximize the usable window, but I'm not sure why. – Jean-Baptiste Yunès Feb 05 '19 at 15:16

1 Answers1

0

As I cannot yet comment I hope this answer is of some use.. according to this man

times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. The return value may overflow the possible range of type clock_t. On error, (clock_t) -1 is returned, and errno is set appropriately.

so it can overflow, yes, and when it does it will go from +2,147,483,647 to −2,147,483,647 if the return is an unsigned long and continue to tick in positive direction. However signed integers are undefined after overflow, this is due to compilers handling them differently for optimization, here.

If my assumption is correct it can overflow multiple times meaning your value could be invalid after overflow if unsigned or the value will be undefined (random) if signed.

KR34T1V
  • 433
  • 2
  • 15