There are some weird monitors that returns invalid data, as zeroed
Horizontal/Vertical Active/Blanking.

This causes edid-decode to crash with a divsion by error exception. This
simple patch avoids so, checking for the divisor before proceeding.

Signed-off-by: Breno Leitao <lei...@debian.org>
---
 edid-decode.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/edid-decode.c b/edid-decode.c
index 7442f8a..4b2cef8 100644
--- a/edid-decode.c
+++ b/edid-decode.c
@@ -1022,6 +1022,17 @@ static int detailed_block(const unsigned char *x,
int in_extension)
                break;
        }

+       if ((ha + hbl) == 0 ||
+           (va + vbl) == 0) {
+               printf("Invalid data. Refusing to continue.\n"
+                      "Horizontal Active %4d\n"
+                      "Horizontal Blanking %4d\n"
+                      "Vertical Active %4d\n"
+                      "Vertical Blanking %4d\n",
+                      ha, hbl, va, vbl);
+               return 0;
+       }
+
        pixclk_khz = (x[0] + (x[1] << 8)) * 10;
        refresh = (pixclk_khz * 1000) / ((ha + hbl) * (va + vbl));
        printf("Detailed mode: Clock %.3f MHz, %d mm x %d mm\n"
-- 
2.17.1


Reply via email to