Repository navigation
fix(builtins): abort declare/local on out-of-range negative subscripts (#635) - #658
Merged
Merged
Conversation
#635) declare -a a=( [-2]=q ) printed AFTER with status 0 and an empty array. GNU computes max+1+ind and, still negative, reports [-2]=q: bad array subscript on the whole word with no AFTER (arrayfunc.c:804-809 + assign_array_var_from_string NULL + bash_variable_assignment_error DISCARD). The assignment route was fixed by #631/#634; the builtin route conflated "no [..] header" with "out of range" and skipped the element. array_assignment_index now resolves 3 states (Index / NoHeader / NegativeOutOfRange); the scan breaks with prior elements kept and the whole word travels up via out-params (append fn -> assign fns -> declare executor fn). declare/local translate at the Executor layer mirroring the arith_eval_failure precedent but with the bare report_error diagnostic (no command: segment): partial already installed, exit 1, DISCARD abort. Eval containment reuses the #637 absorption primitive. export/readonly record failure status with the same diagnostic; their list-abort threading is a documented follow-up. Verification: new 20-case GNU differential 6/20 -> 20/20; new tests/issue635_builtin_oob.rs (10 tests); focused suites green; full serial failure-set gate vs d4d8dc4 identical targets (NEW=0/ DISAPPEARED=0; 2/2 part_080 coproc flake passing in isolation); niubash A/B failure sets byte-identical (49=49).
caomengxuan666
added a commit
that referenced
this pull request
Oct 16, 2026
… (#677) export -a a=( [-2]=q ); echo AFTER printed AFTER rc 0; GNU diagnoses, no AFTER, rc 1 (same readonly -a). export -a/-A delegates to nested declare_builtin (setattr.def:240-268): arrayfunc.c:804-809 any_failed + DISCARD (subst.c:11169). Mirrors declare/local #658: apply arms record oob_word, keep partial store, stop the operand loop; Executor arms print the bare diagnostic, exit 1, raise the #637 evalerror abort. 13 new tests; 18/18 GNU probe matrix. Co-authored-by: caomengxuan666 <[email protected]>
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.
fix(builtins): abort declare/local on out-of-range negative subscripts (#635)
What
declare -a a=( [-2]=q )printedAFTERwith status 0 and an emptyarray. GNU computes
max+1+indand, still negative, reports[-2]=q: bad array subscripton the whole word with noAFTER(
arrayfunc.c:804-809+assign_array_var_from_stringNULL +bash_variable_assignment_errorDISCARD). The assignment route was fixedby #631/#634; the builtin route conflated "no
[..]header" with "outof range" (both
None) and skipped the element.Fix
array_assignment_indexreturns a 3-state enum (Index / NoHeader /NegativeOutOfRange) instead of
Option;[]keeps its historicalappend-next meaning (GNU's err_badarraysub for it is a separate,
deliberately untouched concern).
append_array_valuebreaks the scan on OOB with prior elements keptand reports the whole word up through an out-param; every call layer
(
assign_declare_names, the declare executor fn,export/readonlyvalue computation) threads it without changing failglob handling.
declare/localtranslate at the Executor layer (mirroring thearith_eval_failureprecedent, but with the bare report_errordiagnostic — no
command:segment): partial store already installed,exit 1, DISCARD abort.
export/readonlyrecord failure status withthe same diagnostic; their list-abort threading is a documented
follow-up (no battery coverage there yet).
the abort), so
evalreturns failure with the partial store and thecaller continues.
Verification
(declare/append/local/typeset/eval/subshell/trap/controls).
tests/issue635_builtin_oob.rs(10 tests).compound-quote and neighbors); full serial failure-set gate vs
d4d8dc4:target sets identical (NEW=0/DISAPPEARED=0; branch +1 ok = the new test
file); test-level 2 NEW / 2 DISAPPEARED all in the
known-nondeterministic
part_080family (all four pass in isolation onbranch).
6295367, only rubash[patch]switched): failure sets byte-identical (49=49).
GNU owners:
arrayfunc.c:753-809(header scan),:913-932(assign_array_var_from_string),
subst.c:11169(bash_variable_assignment_error),
arrayfunc.c:63(badsub message).