LCDproc development and user support list

Text archives Help


[Lcdproc] [Patch] Protect against overflow in do_mainloop()


Chronological Thread 
  • From: steve AT nexusuk.org (Steve Hill)
  • Subject: [Lcdproc] [Patch] Protect against overflow in do_mainloop()
  • Date: Tue Sep 19 19:18:02 2006


The attached patch protects against the t_diff calculations overflowing in do_mainloop(). This can happen if the machine has been suspended (e.g. ACPI S3 or S4).

If the calculations would overflow this patch causes the render_lag to be reset to RENDER_FREQ and process_lag to be set to 1. The justification is that if we've been suspended, the measured lag is going to be pretty useless anyway so this should ensure we do a process and render pass immediately.

Obviously most displays won't save state if they're powered down so this code doesn't let you suspend a machine and then recover, although I've been working on some HAL integration for the CFontz 635 which allows you to suspend the machine or unplug the display and then restore the display's state when the machine wakes up or your plug it back in again. However, the HAL code is nowhere near ready for public consumption. :)

--

- Steve

xmpp:steve AT nexusuk.org

sip:steve AT nexusuk.org
http://www.nexusuk.org/

Servatis a periculum, servatis a maleficum - Whisper, Evanescence
Index: server/main.c
===================================================================
--- server/main.c (revision 107)
+++ server/main.c (revision 114)
@@ -43,6 +43,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <sys/types.h>
+#include <limits.h>

#include "getopt.h"

@@ -820,7 +821,16 @@
last_t = t;
#ifndef WIN32
gettimeofday (&t, NULL);
- t_diff = ((t.tv_sec - last_t.tv_sec) * 1e6 + (t.tv_usec -
last_t.tv_usec));
+ t_diff = t.tv_sec - last_t.tv_sec;
+ if ((t_diff + 1) > (LONG_MAX / 1e6)) {
+ /* We're going to overflow the calculation - probably
been to sleep, fudge the values */
+ t_diff = 0;
+ process_lag = 1;
+ render_lag = (1e6/RENDER_FREQ);
+ } else {
+ t_diff *= 1e6;
+ t_diff += t.tv_usec - last_t.tv_usec;
+ }
#else
QueryPerformanceCounter(&t);
/*t_diff.HighPart = t.HighPart - last_t.HighPart;



Archive powered by MHonArc 2.6.18.

Top of page