gcode: guard NULL chained on_settings_changed in onSettingsChanged - #999
Open
ScottW514 wants to merge 1 commit into
Open
gcode: guard NULL chained on_settings_changed in onSettingsChanged#999ScottW514 wants to merge 1 commit into
ScottW514 wants to merge 1 commit into
Conversation
terjeio
reviewed
Aug 3, 2026
gc_init subscribes to grbl.on_settings_changed by capturing the previous handler to chain it. When no plugin or driver has subscribed before the first gc_init, the captured pointer is NULL and the chained call in onSettingsChanged dereferences it - every runtime $-setting write then crashes on drivers with no other subscriber (observed live with the Simulator). The core dispatcher already NULL-checks its own pointer; this adds the same guard to the chained tail.
ScottW514
force-pushed
the
fix-null-on-settings-changed
branch
from
August 3, 2026 10:05
6869c58 to
0f333a6
Compare
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.
gc_init()subscribes togrbl.on_settings_changedby capturing the previous handler so it can chain it:When no plugin or driver has subscribed before the first
gc_init()runs, the captured pointer is NULL, and the chained call at the top ofonSettingsChanged()dereferences it. On builds with no other subscriber, every runtime$-setting write then crashes (observed live with the Simulator: any$xx=yysegfaulted).The core dispatcher in grbllib.c already NULL-checks its own
grbl.on_settings_changedbefore calling; this adds the same guard to the chained tail in gcode.c. No behavior change when a subscriber exists.Reproduce (before this fix): build the Simulator, connect, send any
$-setting write, e.g.$110=6000- the process crashes inonSettingsChanged().