Conversation
Format NMEA messages directly into a caller supplied buffer instead of allocating a new buffer with malloc() on every call. nmea_printf_buffer() is reimplemented on top of the new nmea_vaprintf_buffer() and keeps its previous behaviour: it returns 0 without touching the buffer if the message does not fit, and a NUL terminated string is always produced when it does fit. Adds a unit test for the new formatting path. --AI assistance: this change was AI-assisted, reviewed by a human before submission.
Keep the message and sub-string buffers as class members allocated once for their maximum possible formatted length, instead of creating fresh stack buffers sized by guesswork on every update() call. Sub-strings such as the longitude are now guaranteed to be NUL terminated so they can never be passed unterminated to the %s consumers of the NMEA message formats. --AI assistance: this change was AI-assisted, reviewed by a human before submission.
Author
|
Hi @WickedShell, this PR is ready for review whenever you get a chance. The failing copter test (ModeZigZag) is a known SITL flake unrelated to the NMEA changes. Thanks! |
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.
Summary
Fixes #12514. AP_NMEA_Output no longer allocates a fresh buffer per message. It uses persistent pre-sized message buffers and a new non-allocating formatting helper, fixing latent
snprintfbuffer-size bugs.Classification & Testing (check all that apply and add your own)
Tested with SITL copter build, NMEA unit tests (
tests/test_nmea_vaprint_buffer,tests/test_nmea_print,tests/test_nmea_vaprint), andcheck_branch_conventions.py.Description
AP_Common: addNMEA::vaprint()andNMEA::vaprintf()helpers that format into caller-provided buffers without allocating, plus atest_nmea_vaprint_bufferunit test. Fixes the incorrect buffer lengths passed to the previous::*printfvariants inAP_NMEA_Output.AP_NMEA_Output: store persistent, pre-sized message buffers in the message classes instead of building a temporaryStringper message. This removes periodic heap allocations, moves the data into contiguous memory, and keeps Mavlink copying in one piece.Note: contribution is AI-assisted (written with the assistance of an LLM, reviewed by the human author).