Fix ADSB altitude integer overflow and add on-ground indicator - #3275
Merged
Conversation
- Fix display overflow: use to_string_dec_int (signed) instead of to_string_dec_uint (unsigned) for altitude display - per ICAO Annex 10 Vol IV 3.1.2.6.5.4, altitude = 25N-1000 can be as low as -1000ft - Remove incorrect altitude clamp (altitude < 0 => 0) in DF 0/4/20 decoder - Add on_ground flag to AircraftRecentEntry; set from TC 5-8 (surface position) messages, cleared on TC 9-22 (airborne position) messages - Display 'GND' in altitude column when aircraft is on ground - Clear altitude to 0 when on_ground is set to prevent stale data in map color calculation Closes #3274
Copilot
AI
changed the title
[WIP] Fix integer overflow in ADSB altitude calculations
Fix ADSB altitude integer overflow and add on-ground indicator
Jul 22, 2026
zxkmm
reviewed
Jul 22, 2026
zxkmm
reviewed
Jul 22, 2026
Remove on_ground field, TC 5-8 handling, and "GND" display per review feedback. Only keep the two minimal bug fixes: - Signed altitude display (to_string_dec_int vs to_string_dec_uint) - Remove erroneous altitude < 0 clamp; update comment to show the math
zxkmm
marked this pull request as ready for review
July 22, 2026 03:43
gullradriel
approved these changes
Jul 22, 2026
gullradriel
left a comment
Member
There was a problem hiding this comment.
Good to go, thanks @zxkmm for the review ;-)
Member
|
Np, sorry for pinging, no idea why but I cannot approve this, maybe it’s because I asked copilot to make PR |
Member
|
That's it. You cannot review a PR you provided or contributed ;-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per ICAO Annex 10 Vol IV §3.1.2.6.5.4, barometric altitude is decoded as
25N − 1000ft, yielding valid negative values down to −1000 ft. Landing aircraft were hitting an unsigned cast overflow and a hard-clamp-to-zero, producing junk displays like294967294(screenshot above showsANZ199Lwith this bug).Changes
Integer overflow fix (
ui_adsb_rx.cpp)to_string_dec_uint((unsigned int)(entry.pos.altitude / 100), 4)withto_string_dec_int((int32_t)(entry.pos.altitude / 100), 4)— negative altitudes now display correctly (e.g.-1for −100 ft) instead of wrapping to ~4 billionif (altitude < 0) altitude = 0;clamp in the DF 0/4/20 AC altitude decoderOn-ground indicator (
ui_adsb_rx.cpp,ui_adsb_rx.hpp)bool on_ground{false}toAircraftRecentEntryon_ground = true, zero and invalidate the altitude fieldon_groundwhen TC 9–22 (airborne position) is receivedGND(4 chars, matching column width) in the altitude column when on ground, and use altitude 0 for map color calculation to avoid stale airborne color after landingProof that your changes work
🖥️ Proof it compiles
Pending — build log to be attached.
📱 Proof of testing on a real device
Pending — to be tested at an airfield with aircraft landing near/below sea level.
📡 Proof against a real emitter/receiver (if applicable)
Applicable — ADSB RX decoding. Pending real-device ADSB capture showing corrected altitude values for low-altitude aircraft.
📚 Wiki documentation commitment
Checklist