Skip to content

GH-49110: [C++] Add bounds checking to DataType::field() to return nullptr for out-of-bounds access#49111

Open
HyukjinKwon wants to merge 1 commit intoapache:mainfrom
HyukjinKwon:GH-49110
Open

GH-49110: [C++] Add bounds checking to DataType::field() to return nullptr for out-of-bounds access#49111
HyukjinKwon wants to merge 1 commit intoapache:mainfrom
HyukjinKwon:GH-49110

Conversation

@HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented Feb 2, 2026

Rationale for this change

Previously, DataType::field(int i) directly accessed children_[i] without bounds checking, resulting in undefined behavior for out-of-bounds indices. This could crash or return garbage.

What changes are included in this PR?

Added bounds checking to DataType::field() to return nullptr for out-of-bounds access, matching the behavior of GetFieldByName().

Are these changes tested?

Yes, added TestStructType.FieldAccessOutOfBounds to verify that out-of-bounds indices return nullptr.

Are there any user-facing changes?

Yes. DataType::field(i) now safely returns nullptr for invalid indices instead of undefined behavior.

@github-actions
Copy link

github-actions bot commented Feb 2, 2026

⚠️ GitHub issue #49110 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant