spring: Avoid looping if time appears to be going backwards

Since the time values are unsigned integers we can check whether the msec is
smaller than spring->timestamp by checking if the subtraction overflows into a
value greater than half the maximum unsigned integer range (ie. top bit set)
Rob Bradford 12 years ago committed by Kristian Høgsberg
parent 552d12b10e
commit c4f3338745
  1. 8
      src/util.c

@ -46,6 +46,14 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
{
double force, v, current, step;
/* Avoid entering into an infinite loop */
if (msec - spring->timestamp > UINT32_MAX / 2) {
weston_log("timestamps going backwards (from %u to %u)\n",
spring->timestamp, msec);
spring->current = spring->previous = spring->target;
return;
}
step = 0.01;
while (4 < msec - spring->timestamp) {
current = spring->current;

Loading…
Cancel
Save