summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2022-04-13 14:14:07 +0100
committerRichard Hughes <richard@hughsie.com>2022-04-13 14:14:07 +0100
commit972653e6ebde446ca2cf1d1fa8cf2bc1665becde (patch)
tree8352f116d8c79807b0a9efaaa2a96045313c55bf
parentf0eba69e35254c262bbcec8511faa47d952ef99c (diff)
downloadcolord-972653e6ebde446ca2cf1d1fa8cf2bc1665becde.tar.gz
huey: Fix potential crash when reading from broken hardware
-rw-r--r--src/sensors/huey/huey-ctx.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/sensors/huey/huey-ctx.c b/src/sensors/huey/huey-ctx.c
index fa9052e..09f83ea 100644
--- a/src/sensors/huey/huey-ctx.c
+++ b/src/sensors/huey/huey-ctx.c
@@ -309,9 +309,12 @@ huey_ctx_take_sample (HueyCtx *ctx, CdSensorCap cap, GError **error)
color_native.R, color_native.G, color_native.B);
/* try to fill the 16 bit register for accuracy */
- multiplier.R = HUEY_POLL_FREQUENCY / color_native.R;
- multiplier.G = HUEY_POLL_FREQUENCY / color_native.G;
- multiplier.B = HUEY_POLL_FREQUENCY / color_native.B;
+ if (color_native.R != 0)
+ multiplier.R = HUEY_POLL_FREQUENCY / color_native.R;
+ if (color_native.G != 0)
+ multiplier.G = HUEY_POLL_FREQUENCY / color_native.G;
+ if (color_native.B != 0)
+ multiplier.B = HUEY_POLL_FREQUENCY / color_native.B;
/* don't allow a value of zero */
if (multiplier.R == 0)