-
Notifications
You must be signed in to change notification settings - Fork 18.6k
AP_Terrain: Protect against division by 0 when TERRAIN_SPACING is less then 1 #29653
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
base: master
Are you sure you want to change the base?
Conversation
This probably needs to move to being a float at some stage to allow for sub-metre terrain grids. When we do that we'd have to find all of these places again, which would be unfortunate. Did you consider throwing a |
I hadn't considered it, but I do agree, throwing a I can give it a try. Where do you think would be the best place to throw it? |
Hi @peterbarker. I've been digging into the suggestion you made and I have a few questions. Should I do the verification (and subsequently throw the Thanks! |
Hmm. Doesn't look like terrain has a So I think not with Since this should be short-term until we change the spacing to be float, we could probably add a pre-arm check for it. So that's just an additional clause in It's entirely possible when we take this solution to DevCall that the response will be, "no, just make it a float". Did you want me to take this to DevCall before you do the work instead of after? |
I don’t mind doing the pre-arm check, but I agree it might be worth bringing it to DevCall first to see what the consensus is. If you’re okay with that, feel free to raise it there before I dive into the patch. |
@tiagoc-santos please change it so that AP_Terrain::pre_arm_checks() return false with an error message if spacing <= 0 |
Done! Let me know if you need me to rebase and/or squash the commits. |
Prevents a division by 0 error by checking if TERRAIN_SPACING is 0
42cb059
to
3ef0cf3
Compare
Yep, that's the ticket.
I've just done that (before reading your offer here - sorry!) Marking as MergeOnCIPass |
This fixes #29392. In the calculate_grid_info function and the east_blocks function of AP_Terrain, the TERRAIN_SPACING parameter is used to determine grid spacing and how many blocks are needed in a stride for a given location.
When this parameter is set to a value less than 1, a division by zero occurs, leading to an arithmetic exception. This fix ensures that grid_spacing is properly handled when its value is below 1. Specifically, if grid_spacing is less than 1, the system defaults to using a value of 1 instead.
This fix has been tested in SITL environment and seems to be working fine.