Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

survive_disambiguator.c: handle_lightcap: early out with false when _le->length == 0 #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/survive_disambiguator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down