[PATCH v3] edid-decode: Avoid division by zero

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. On invalid data,
it prints something as:

  ...
  Invalid Detailed Timings:
  Horizontal Active/Blanking 32/0
  Vertical Active/Blanking 0/0
  ...

Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
 edid-decode.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/edid-decode.c b/edid-decode.c
index 7442f8a..2612e70 100644
--- a/edid-decode.c
+++ b/edid-decode.c
@@ -1022,6 +1022,14 @@ static int detailed_block(const unsigned char *x, int in_extension)
 		break;
 	}
 
+	if (!ha || !hbl || !va || !vbl) {
+		printf("Invalid Detailed Timings:\n"
+		       "Horizontal Active/Blanking %d/%d\n"
+		       "Vertical Active/Blanking %d/%d\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




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux