From 9516d164d9cd50165b624756583a4d7bfd93733d Mon Sep 17 00:00:00 2001 From: Thomas Thron Date: Mon, 21 Oct 2024 13:45:33 +0200 Subject: [PATCH] survive_disambiguator.c: handle_lightcap: early out with false when _le->length == 0 --- src/survive_disambiguator.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/survive_disambiguator.c b/src/survive_disambiguator.c index d0f8d1cc..f2ef26c5 100644 --- a/src/survive_disambiguator.c +++ b/src/survive_disambiguator.c @@ -38,7 +38,16 @@ bool handle_lightcap(SurviveObject *so, const LightcapElement *_le) { // Gen2 devices can trigger this on startup; but later packets should // reliably change to lh_version == 1. If we see 50+ lightcap packets // without these gen2 packets we can just call it for gen1. - assert(_le->length > 0); + + SurviveContext *ctx = so->ctx; + + // "assert(_le->length > 0);" sometimes breaks the whole program, so instead just return success = false and go on + uint16_t le_length = _le->length; + if (le_length == 0 ) { + SV_WARN("LightcapElement has zero length [SensorId:%d] [Timestamp:%04hX]", _le->sensor_id, _le->timestamp) + return false; + } + if (so->ctx->lh_version == -1) { disambiguate_version *dv = so->disambiguator_data; if (dv == 0) { @@ -47,8 +56,6 @@ bool handle_lightcap(SurviveObject *so, const LightcapElement *_le) { dv->total_count++; - SurviveContext *ctx = so->ctx; - // If the device is close to the LH, it's very possible to see lengths in this range. To prevent false // positives while on gen2; we also check the timing -- it must see x correctly distanced 60/120hz pulses // of the right length to get flagged in. This should be pretty solid -- LH2 all operate at <55hz, so they