tmm1/stackprof

Undefined behavior with interval > 1 second

benbuckman opened this issue · 0 comments

The code to translate interval (set in microseconds) to a timer is implemented here,

timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = NUM2LONG(interval);

and (for forks) here,
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = NUM2LONG(_stackprof.interval);

it_interval is a timeval, documented at https://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html says (emphasis mine),

long int tv_usec
This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million.

What is supposed to happen if interval (passed to start or run) is >= one million?

It looks like the timeval itself will take that value, but the behavior is undefined.

Should StackProf error if the interval is larger than one million? Or should it split the interval over seconds + microseconds?

Thank you