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:42:28 +0100
commitc357ea2e1f65b5127a33960e89163245355a4d7c (patch)
treebf155cef457c7bb4dee016f3efe020a3e3312549
parent41bf6b99a11ccf4235aa946a3bc9fc37ea4ee4d9 (diff)
downloadcolord-c357ea2e1f65b5127a33960e89163245355a4d7c.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)