Use int.TryParse for the vehicle-reported RALLY_TOTAL and FENCE_TOTAL - #3777
Open
nicholasaleks wants to merge 1 commit into
Open
nicholasaleks wants to merge 1 commit into
nicholasaleks wants to merge 1 commit into
Conversation
The post-connect block reads these two with int.Parse(param[...].ToString()). A vehicle chooses both the value and the reported type of any parameter it sends, and MAVLinkParam.ToString() returns the raw REAL32 for a REAL32, so the string can be "3.5", "NaN" or "1E+30". int.Parse throws FormatException on all three, and OverflowException on an integer above int.MaxValue. The throw is not contained. The call sits in the if condition, &&-chained ahead of showui, so short-circuit evaluation runs it as soon as ContainsKey is true and before the try that opens on the following line. The surrounding post-connect block is the body of a BeginInvokeIfRequired lambda with no try/catch of its own, so the exception either unwinds into doConnect's catch and aborts the connection, or reaches Application.ThreadException and raises the generic error modal. Either way the operator cannot finish connecting, and the remaining post-connect setup does not run. No interaction is involved: parameters are downloaded automatically on connect. int.TryParse removes the throw without depending on where the call sits relative to the try, and a count that is not an integer now reads as absent, which is the right reading of a malformed value.
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.
The post-connect block reads these two with int.Parse(param[...].ToString()). A vehicle chooses both the value and the reported type of any parameter it sends, and MAVLinkParam.ToString() returns the raw REAL32 for a REAL32, so the string can be "3.5", "NaN" or "1E+30". int.Parse throws FormatException on all three, and OverflowException on an integer above int.MaxValue.
The throw is not contained. The call sits in the if condition, &&-chained ahead of showui, so short-circuit evaluation runs it as soon as ContainsKey is true and before the try that opens on the following line. The surrounding post-connect block is the body of a BeginInvokeIfRequired lambda with no try/catch of its own, so the exception either unwinds into doConnect's catch and aborts the connection, or reaches Application.ThreadException and raises the generic error modal. Either way the operator cannot finish connecting, and the remaining post-connect setup does not run. No interaction is involved: parameters are downloaded automatically on connect.
int.TryParse removes the throw without depending on where the call sits relative to the try, and a count that is not an integer now reads as absent, which is the right reading of a malformed value.
Related to: https://github.com/nicholasaleks/infected-drones/tree/main/MP-04_param_total_connect_dos